r/django icon

Go to django

How to load static files while deploying using nginx

Hosting and deployment

Archived post. New comments cannot be posted and votes cannot be cast.

Thumbnail image: Launch Your Django App into Orbit

  1. 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/ {

                alias /my/local/path

}

Good luck

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

More replies

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

More replies More replies

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)

Thumbnail image: Korbit’s AI-Powered Code Review Agent helps your team ship better code, faster.

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

location /static/ {
  alias path
}

make sure your path was an / in the end. /app/static/