Django Day02 (tags, static file, template inheritance)

1, tags labels

(1) for the label
format: {% for temporary traverse in sequence endfor% {...}%}%
HTML file:
Here Insert Picture Descriptionviews file:
Here Insert Picture Descriptionurls documents:
Here Insert Picture DescriptionHTML :( results of which I form some modifications)
Here Insert Picture Descriptionto true-the Result:
Here Insert Picture Description

2, if-elif-else tag

html file:
Here Insert Picture Description
views file:
Here Insert Picture Description
urls file:
Here Insert Picture Descriptionresults map:
Here Insert Picture Description

3, load and static labels

When we want to use some static resources such as images, js, css on the page. This time we will have to use a static label.
now, we now display pictures on a Web page, the figure has actually shows up!
Of course views files, urls file is very simple, it does not show up in
(1) to create a static folder, and file templates juxtaposed, (static can easily named), then put in a picture;

Here Insert Picture Description
(2) is arranged in the settings file
Here Insert Picture DescriptionFurther, one can add,
Here Insert Picture Descriptiondisplay (3) further html file
Here Insert Picture Description(4) Results FIG.
Here Insert Picture Description

4, template inheritance

When we visit some websites, you will find some pages section of the website is the same, such as the navigation bar, or at the bottom, this time we can reduce the amount of code by way of inheritance template.
(1) prepared three pages, in which the same part of the contents,
(2) we put these same parts, made a base.html, and add a small interface such that it can use its html expanded
base of small files interface:
Small connector base file

(3) we were in three html file, add their different parts,
Here Insert Picture Description
(4) This made a simple example

Guess you like

Origin blog.csdn.net/qq_39062888/article/details/89501350