How to load static files while deploying using nginx
Hosting and deployment
Everything is working fine except for static files I only have STATIC_URL and staticfiles app is in my INSTALLED_APPS in my settings file and when I request the admin page i get response without styling What should I do to load the static file
Archived post. New comments cannot be posted and votes cannot be cast.
Sort by:
Best
Open comment sort options
Best
Top
New
Controversial
Old
Q&A
When deployed you need to run manage.py collectstatic, this is what moves your files to you static_dir
Then in nginx config, you need to set access to the static url:
I did:
location /static/ {
}
Good luck
Same for media files
It finally worked after I traced the error it was because of misspelling in the path Now i have couple of things to understand In deploying why do i need static_root and staticfiles_dirs when it works with just static_url and collectstatic
https://wolfx.io/how-to-serve-static-and-media-files-in-nginx
I did these earlier
STATIC_URL = '/static/' STATICFILES_DIRS = [ os.path.join(BASE_DIR, 'static'), ] STATIC_ROOT = os.path.join(BASE_DIR, 'static') I restarted the service and it didn’t work
You can use whitenoise. https://github.com/evansd/whitenoise
Go into your Linux and navigate to one of your actual static files. Then type pwd, which will print the current path
So if your static file is 'logo.jpg' and the path is /home/deepholedeveloper/project/static/images/logo.jpg
Then you want nginx to point to /home/deepholedeveloper/project/static/
Basically, Nginx is serving your static so it doesn't really matter where Django points to. All that matters is where you've put your collectstatic files (and if you haven't run collectstatic yet, do that)
Comment deleted by user
Oh jeez. This comment is a mess. There's a lot wrong with it. Please delete it
its common problem in nginx but the solution was to use location
make sure your path was an / in the end. /app/static/