Yes, this is true for two different situations.
During development, you place your static files in either (or both) app ‘static’ directories and your project ‘static’ directory.
Then, for deployment, you run collectstatic
to copy those files (in addition to system-provided static files in their directories) to a “common location” defined by STATIC_ROOT to be accessed by your webserver (e.g., nginx).
STATIC_ROOT defines the directory to which all the static files will be copied.
STATIC_URL identifies what url to use as the “prefix” to reference those files.
If you’re using nginx as your webserver, then it’s the nginx configuration that maps the url to the physical directory.
For example, if STATIC_ROOT is /var/www/myproject/static
, and STATIC_URL is 'static/'
, then you might have an alias directive that looks like this:
location /static/ {
alias /var/www/myproject/static/;
}
(You may also wish to read: Django and Nginx permission issue on Ubuntu - #2 by KenWhitesell)
Side note: To avoid naming conflicts between files with the same name in different apps, you should have a directory named the same as the app within the app static directory. See How to manage static files (e.g. images, JavaScript, CSS) | Django documentation | Django, especially including the box labeled “Static file namespacing”.
This is also covered in the official tutorial at Writing your first Django app, part 6 | Django documentation | Django.
This means that if those three admin.css files are different, they should actually be at:
/home/project/
app1/
static/
app1/
admin.css (1)
app2/
static/
app2/
admin.css (2)
app3/
static/
app3/
noadmin.css (1)
static/
admin.css (3)
Your reference to these admin.css files would then be something like {% static 'app1/admin.css' %}
This leads us to:
This is not something that the rendering engine handles (or even can handle) itself. You either need to create a block in the base template that your app template can use to define which css file to use, or a context variable, or create a context processor. But if you want a different static file to be used by an app, it’s up to you to manage that requirement.