Writing_first_django_app_part6
In Django, some of the additional files in the Web application, such as image, JS, CSS, etc., are called static files "static file"
Django.contrib.staticfiles: collect static files from each application and put them in a separate location for easy use and management
Using CSS
Static file lookup path when the same as template, first in the polls directory to create a directory static, in the inside to create a polls directory, in this polls directory to place static files, now create a file style.css, that is polls/static /polls/style.css, we can find the path directly polls/style.css when we find it.
# Polls/static/polls/style.cssli a { color:green;}
Render the list Green
Then in index.html to introduce this CSS file, as normal HTML, in the beginning of the polls/templates/polls/index.html add:
{% load staticfiles%}<link rel= "stylesheet" type= "Text/css" href= "{% static ' polls/style.css '%}"/>
{% static %}
This tag will give us the absolute path of generating the static file. Now restart the server to see the green font
Adding a Background-image
Create the background file Polls/static/polls/images/background.gif, and then add the following in the CSS file:
Body { background:white url ("images/background.gif") no-repeat right Bottom;}
You can set the background
Django Tutorial Part6