Django tag inheritance

<!DOCTYPE html>



Title

    {% for i in l1 %}
  • {{ i }}
  • {% endfor %}
    {% For foo in l1 reversed%} # circular list is traversed backward flip puppy formula :( front begins to send start, from the back into the start)
  • {{ i }}
  • {% endfor %}
    {% For key in dic.keys%} loop dictionary keys
  1. {{ key }}
  2. {% endfor %}
    {% For v in dic.values%} dictionary cycle value {% endfor%}
    {% for k,v in dic.items %}
  1. {{ k }} : {{ v }}
  2. {% endfor %}

{{Forloop.counter}} counting the number of cycles
{{forloop.last}} is determined is not the first cycle
after the {{forloop.first}} is not determined cycle rate
{{forloop.parentloop.counter}} counting parent the number of cycles label

if tag
statement supports and, or, ==,>, <, <=,> =, in, not in, is, is not determined, the spaces on both sides attention condition
{% if num == 11%}
answered correctly, reward you a kiss
{% else%}

You do not on my bed tonight

{% endif %}

Multi-conditional

{% if num > 100 or num < 10 %}

Your wrong size, you go right next door


{% elif num > 88 and num < 100 %}

You come, you are completely appropriate to my request


{% else %}

It is not right, you come in, anyway, than there is no cool

{% endif %}

Filtration binding using
{% if user_list | length> 50 %}

So big, that his aging mother tonight free


{% else %}

200 yuan primary


{% endif %}

with label


{% With l1.1.name as sb%} of a data call from a long name, using only the internal label with
{SB} {}
{}% endwith The%

csrf_token by csrf authentication mechanisms
in the form inside page form (Form note in form inside) on any position to write {% csrf_token%}, replace this thing became a template when rendering <input type = "hidden" name = "csrfmiddlewaretoken"

Master inheritance
is like a brothel when soliciting always in a room is ready, everyone came and constant or whether they are in a happy Hu Bin bed, a person can not be re-arranged a room, a bed spread, if it is so tired prostitute, reducing the physical prostitutes, reduces the efficiency of prostitutes. to slow money, so when received the original room took one-off like that is inherited
to avoid excessive duplication of code occurs resulting in reduced efficiency computer

Custom master

<!DOCTYPE html>



{% block title %}My amazing site{%/span> endblock %}

{% block content %}{% endblock %}

The master, we call it base.html, she defines a simple HTML skeleton may be two editions of the page layout. Submasters job is to fill their content block

Subtitled looks like
{% extends "base.html"%}

{% block title %}My amazing blog{% endblock %}

{% block content %}
{% for entry in blog_entries %}

{{ entry.title }}


{{ entry.body }}


{% endfor %}
{% endblock %}

extendsTag is the key here. It tells the template engine that this template "inherited" another template. When the system processes the stencil template, firstly, it will locate the parent template - in this case, is "base.html".

  At that time, the template engine will notice base.htmlthe three blocklabels, and with the contents of the sub-template to replace the block.

Guess you like

Origin www.cnblogs.com/x-h-15029451788/p/11890559.html