Static file path Setting official description
1. Make sure this django.contrib.staticfiles is included in your Installed_apps.
2. In your settings file, define Static_url, for example:
Static_url = '/static/'
3. Store your static files in a folder called the static in your app. For example My_app/static/my_app/myimage.jpg.
4. In your templates, either hardcode the URL like/static/my_app/myexample.jpg or, preferably, use the static template Ta G to build the URL for the given relative path by using the configured staticfiles_storage STORAGE (This makes it Much easier when you want to switch to a content delivery network (CDN) for serving static files).
{% load staticfiles%}
Working with instances
In the previous example, we used the third method above, in the app directory, created the static directory, which also created the name of the same as the name of the app directory, the only place static resources files, the path such as:
POLLS/STATIC/POLLS/STYLE.CSS, used when introduced in template
{% load static%}<link rel= "stylesheet" type= "Text/css" href= "{% static ' polls/style.css '%}"/>
One, Django project default read static file directory such as/projectname/appname/static/
Second, if we do not want to put static files in the app or even under the project directory, you can set the staticfiles_dirs in settings.py, such as:
Staticfiles_dirs = ( ' d://static/', # os.path.join (Base_dir, "static"), # '/var/www/static/',)
Then the previous example, when creating D://STATIC/POLLS/STYLE.CSS
Li a { color:red;} Body { background:white url ("images/background.jpg") no-repeat center Top;}
Refresh the page to find that the text color in the link is changed from the original green to red, indicating that the CSS path referenced by the page takes effect
Django Basics, Day9-static file directory with path setup instructions (eg. images, JavaScript, CSS)