Briefly reviewing the two key settings:
STATIC_ROOT
= The location where static files are going to be copied using the collectstatic
command.
The user running collectstatic
must have “write” permissions to that directory, including the ability to create subdirectories.
The web server must have “read” permissions to this entire directory tree.
In the common case, this directory should be outside your project directory. It’s actually quite common to define this within /var/www/
or even /var/www/html/
on Unix-style systems.
STATIC_URL
= The base URL for creating references to static files. This setting has no meaning with Django, other than for creating URLs being referenced within the static
tag used in templates.
This is the URL path that you will associate with STATIC_ROOT
in your web server configuration.
For example, if you have:
STATIC_ROOT = '/var/www/html/project1'
and
STATIC_URL='/static/'
Then your web server needs to be configured such that the location /static
causes the web server to retrieve files from /var/www/html/project1
The most common issues I see with handling static files include:
- Using a
STATIC_ROOT
inside the project directory - Not assigning proper permissions to the
STATIC_ROOT
directory. - Not having the web server configured to map
STATIC_URL
toSTATIC_ROOT
- Not running
collectstatic