Differences and usage of block extends include
1. define the basic template. Define multiple block blocks in the HTML content. The block is determined by whether to replace these blocks by referencing block blocks with the same name in the subtemplate.
{% Block title %} some content, which is not specified here {% endblock %}
{% Block content %} some content, which is not specified here {% endblock %}
{% Block footer %} some content, which is not specified here {% endblock %}
Here title content footer is not a variable and its name is customized
Blockgeneral definition in base.html, block is the area where content can be added to the HTML that inherits the base.
Ii. subtemplate Reference Method
{% Extends "base.html" %}
{% Block title %} the current time {% endblock %}
{% Block content %} <p> it is now {current_date }}. </P> {% endblock %}
The first sentence is a fixed format and must be the first template tag in the template.
Extends parameters are generally strings and can be variables.
The portable path and relative path are based on the template directory of template_dirs.
The sub-template determines the block to be replaced, so you do not need to pay attention to other parts. If there is no defined block, you do not need to replace it. Instead, you can directly use the block of the parent template.
3. reference the upper-level code block and make some modifications based on It {block. Super }}
{% Block footer %}
{Block. Super }}
Aaaaa
{% Endblock %}
Django template system-the template contains another template include
After using the template to load the API mechanism, other template tags are available.
{% Include 'nav.html '%}
{% Include "nav.html" %}
The portable path and relative path are based on the template directory of template_dirs.
{% Include 'endpoints/nav.html '%}
Variable name
{% Include template_name %}
All included variables are processed in a unified manner, with no distinction between the layer-7 templates
Django {block. Super} template tag
The {block. Super} tag in the Django template is very useful. It can not only overwrite the parent template, but also Append content based on the parent template. Of course, it can also be overwritten.
This gives us flexibility: it can be completely rewritten, reused, or extended based on reuse.
2. Locals () Skills
Locals () returns a dictionary containing all the variables and their values in the current scope.
From Django. Shortcuts import render_to_response
Import datetime
Def current_datetime6 (request ):
Current_date = datetime. datetime. Now ()
Return render_to_response('current_datetime6.html ', locals ())
Django template system learning