Django Tutorial Part6

Source: Internet
Author: User
Tags django tutorial

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.