Filter in python html doraemon, if, for conditionals

# ## in the HTML Filter filter 11.4 

the MVC and the MTV

 - the MVC:
   - M: Model Model
   - V: View View the HTML
   - C: Controller Controller - transfer instruction router, business logic
 - the MTV:
   - M: the ORM Model Module
   - T: template template the hTML
   - V: View business logic 

relationships between the templates and variables

 - variables are received by {} in html
 - methods: method index .key property...
   - {{index List}.} - forward index
   - {{dic.keys}}
   - {{dic.value}}
   - {{dic.items}}
   - {{}} pub.name 

# ### filter filters 11.4.1 

syntax: { value { |filter_name: Parameter}} 

Built-in Filter

 - {{default value | default: " Nothing " }}   # variable name does not exist or is empty, the default value is displayed
 
- the size of the file filesizeformat

 - the Add corresponds addition, the string splicing splicing, the list

 - {{slice Hobby | slice: " -2: 0: -1 " }} sections

 - DATE {{now | DATE: " Ymd H: I: S " }}

 - `` `Python
   # Setting configuration (default formatting time): 
  USER_L10N = False 
  DATETIME_FORMAT = ' Ymd H: I: S ' 
  `` `

 - safe pass if HTML statements, will be safe handling, converted to a string, can safe html statement direct delivery

 -Take a length of length

 - the Join list string concatenation

 - First take the first

 - Last taken last 



custom filter

 . 1 . Create a python named templatetags in App
 2 . py file created in python, since the file name is defined as any name. For example (my_tags.py)
 . 3 . In the file write: 

`` `Python 
from Django Import Template 

Register = template.Library ()    # Register does not alter 
`

    4. Write function + decorator 

`Python 
@Register .fliter 
DEF add_xx (value, Arg)    # up to two parameters 
    return  " {} - {} " .format (value, Arg) 
`` `

    . 5Use in html 

`` `html 
{ % Load my_tags% } 
{{ ' liujia ' | add_xx: ' Nb ' }} 
` `` 



# ## 11.5 Analyzing for loops and if 

`` `html 
{ % for Book in all_book % }
     <TR> 
        .......
     </ TR> 
{ % empty% }
     <TD colspan = ' S ' style = ' text-Algin: Center ' > no data </ TD>     # when circulating the list is empty 
{% endfor% } 
`` ` 

foorloop

HTML `` ` 
{ % for I in List% } 
    {} {I} 
    {} {} forloop.conuter 
{ % endfor% } 

counter 1 starts 
conuter0 from 0 
recounter to an end 
recounter0 0 to the end of 
` `` 



with 

` HTML `` 
{ % with new new variable% AS } 
{} {} new new 
{ % endwith The% } 
`` ` 



continuous determination

 - Python 10>. 5>. 1 ----> 10>. 5 and . 5>. 1 ----- > to true
 - JS 10>. 5>. 1 ------> 10>. 5 ---> to true> -----. 1 to false
 - not supported on the template determination, does not support arithmetic 

csrf_token

 -csrf CSRF
 - the browser acquires the form of bank forms from the fishing site, and then pass the completed form to bank fraud, transfer

 

Guess you like

Origin www.cnblogs.com/doraemon548542/p/11609112.html