Thank you for clarifying. I was unaware that static files should be moved outside of the Django project directory in production.
Hi, does anybody have an idea. In Test, I am
Django 4.2.1
Nginx serving the admin static files
Static files are all loaded in the browser, and available, no errors,
Still the admin pages are using the user agent sheet which messes up the styling and usability
In case anyone comes across this thread like I did while debuggingâŚ
I was running a Django instance via nginx and had upgraded the version of Django several major/minor versions and observed 404s on several admin static files. My Django root directoryâs static files contained the files that were showing up as not found.
This was caused by the nginx config looking in the wrong location:
# Proxy the static assests for the Django Admin panel
location /static/admin {
alias /usr/lib/python3/dist-packages/django/contrib/admin/static/admin/;
}
Which contained old static files incompatible with the newer version of Django.
The correct solution was to upgrade Django globally, or if thatâs not possible, update the config to point at the correct location.
Welcome @tomwalters !
Actually, if youâre properly deploying Django using collectstatic
, then this wouldnât be necessary. The static admin resources would be collected like the rest of the static resources and copied to STATIC_ROOT
.
The admin app is an app, like every other app. There is no reason to manage it differently.
Hi Ken, I recently created a django project which includes a wsgi web server. Iâm trying to deploy it to an aws ec2 instance (t2.micro ubuntu) but after lots of trying and back and forth the server canât find the static files used for the django admin, please assist
Welcome @angellox7 !
Please specify how youâre running your project, and the configuration you are using with the web server for your static files.
Also, see the responses and threads at:
- Deploy Static files - #3 by KenWhitesell
- Django Static Files issue with Nginx - #2 by KenWhitesell
(There are many others, but the ones I found quickly are mostly just more of the same.)
I was working on troubleshooting the issue, no luck yet, Iâm using Nginx with gunicorn, the server is already running and serving the app but the admin static files donât load.
Iâm still unsure how to set up nginx to serve static files including the Django admin. looking forward to hearing from you. thank you.
Please open a new topic for this discussion.
When you do, please provide the details of your configuration and your settings.
Weâll need to see the appropriate sections of your nginx configuration and the settings.py file, along with the commands that you are using to perform your deployement and run your system.
Do not post descriptions of what youâre trying to do, post the actual file contents and commands being used.
Hi @KenWhitesell, I could finally troubleshoot the issue, now I have my nginx properly running and serving static files!! Thanks for your kind support!
Hello,
Not sure if the issue is resolved or not but if someone have the same issue, below is the solution that iâve applied.
When you deploy you application, you collect the static file through
python manage.py collectstatic
So, django will copy all the static file on a dir. For example for me, the the static files on /var/www/website/src/staticfiles
So, after, you need to specify on apache that the static file are at this location :
Alias /static/ /var/www/website/src/staticfiles/
Restart apache and itâs will work.
If cleaning the cache with CTRL + F5 did not work, here is the solution.
1- Make a comment line STATICFILES_DIRS.
2- Define a meaningless path for STATIC_ROOT.
3- Run âpy manage.py collectstaticâ.
4- Delete conflicting folders before placing the files in the path you specified STATIC_ROOT in your main static file.
5- Now you can paste the new files in place of the files you deleted.
6- Clear the cache with CTRL + F5.