You might have came across a situation where your application works perfectly fine on local machine but when deployed to production, everything works except admin section, technically it functions as expected but it does not have CSS. Why this happens ?
If you want to recreate this problem, just following in settings.py
from True to False.
DEBUG = False
Step#1 collectstatic
$python3.6 manage.py collectstatic.
Step#2 Change server config.
When you are running, runserver
, you are running development server and it does a lot of things for you, including serving of static files but in production, Django expects that the static files will be served by your serer.
This is not difficult at all, just have below changes done to your nginx server config.
server {
server_name domainname.com www.domainname.com;
location / {
include uwsgi_params;
uwsgi_pass unix:/run/uwsgi/domainname.sock;
}
location /static { # add this
alias /var/www/domainname/static; # add this
} # add this
}
if you are hosting django application using uwsgi and NGINX, this will work for you. I am not sure about gunicorn server. You can check post deploying django with uwsgi and nginx for deployment of your application to server.
First make sure you application is working on production server and then work on to make admin successfully. Deploying Django to server has its own challenges, don’t make it more complicated by adding this change too. Attack problems one at a time.
Please let me know if you faced any issue while getting this working.