Django模板语言和模板 整理

  • 傻萌新的templates

小白如我一开始是使用思路为return HttpResponse("hello world")的方式来返回到前端呈现的。

  • 思路点拨

看了大佬们的博客,明确了症结:这种方式把数据和视图混在一起,不符合Django的MTV思想。

  • 正常人的templates

<h1>{{ hello }}h1>


现在开始学习

首先放上我学习的博客:

https://blog.csdn.net/HuangZhang_123/article/details/70255545

https://www.cnblogs.com/6324TV/p/8672021.html

https://www.cnblogs.com/CongZhang/p/5944463.html

https://blog.csdn.net/inuyasha1121/article/details/43952073

需要记两种特殊符号:

{{  }}和 {% %}

变量相关的用{{ }},逻辑相关的用{% %}


 {%ttttt%}是模板标签,{{vvvv}}是模板变量,{{eee|jjj:...}}是过滤器形式


变量

{{ 变量名 }}

  1. 变量名由字母数字和下划线组成。
  2. 点(.)在模板语言中有特殊的含义,用来获取对象的相应属性值。

下面是使用(.)的例子:

views.py中的代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
def  template_test(request):
     =  [ 11 22 33 ]
     =  { "name" "alex" }
 
     class  Person( object ):
         def  __init__( self , name, age):
             self .name  =  name
             self .age  =  age
 
         def  dream( self ):
             return  "{} is dream..." . format ( self .name)
 
     Alex  =  Person(name = "Alex" , age = 34 )
     Egon  =  Person(name = "Egon" , age = 9000 )
     Eva_J  =  Person(name = "Eva_J" , age = 18 )
 
     person_list  =  [Alex, Egon, Eva_J]
     return  render(request,  "template_test.html" , { "l" : l,  "d" : d,  "person_list" : person_list})

html模板中支持的写法:

1
2
3
4
5
6
7
8
{ # 取l中的第一个参数 #}
{{ l. 0  }}
{ # 取字典中key的值 #}
{{ d.name }}
{ # 取对象的name属性 #}
{{ person_list. 0.name  }}
{ # .操作只能调用不带参数的方法 #}
{{ person_list. 0.dream  }}

当templates引擎遇到变量时,引擎使用变量的值代替变量。使用(.)访问变量的属性,比如{{d.name}}。当templates引擎遇到(.)的时候,会按照如下顺序查找:

  1. 字典查找,例如:foo['bar']  
  2. 属性查找,例如:foo.bar  
  3. 方法查找,例如:foo.bar()  
  4. list-index查找,例如foo[bar]  


模板的大致结构(后面有详细)

Django的templates(templates:模板),它是一个string文本。templates用来分离一个文档的表现形式和内容(也可以说成数据)。templates定义了placeholder(placeholder:占位符)和表示多种逻辑的tags(tags:标签)来规定文档如何展现。通常templates用来输出HTML,但是Django的templates也能生成其他基于文本的形式。

模板大致结构:

<html>
<head><title>Ordering noticetitle>head>
<body>
<h1>Ordering noticeh1>
<p>Dear {{ person_name }},p>
<p>Thanks for placing an order from {{ company }}. It's scheduled to
ship on {{ ship_date|date:"F j, Y" }}.p>
<p>Here are the items you've ordered:p>
<ul>
{% for item in item_list %}
    <li>{{ item }}li>
{% endfor %}
ul>
{% if ordered_warranty %}
    <p>Your warranty information will be included in the packaging.p>
{% else %}
    <p>You didn't order a warranty, so you're on your own when
    the products inevitably stop working.p>
{% endif %}
<p>Sincerely,<br />{{ company }}p>
body>
html>

例子中,

用两个大括号括起来的文字(例如 {{ person_name }} )称为 变量(variable) 。这意味着在此处插入指定变量的值。

被大括号和百分号包围的文本(例如 {% if ordered_warranty %} )是 模板标签(template tag) 。标签(tag)定义比较明确,即: 仅通知模板系统完成某些工作的标签。

这个例子中的模板包含一个for标签( {% for item in item_list %} )和一个if 标签({% if ordered_warranty %} )

for标签类似Python的for语句,可让你循环访问序列里的每一个项目。 if 标签,正如你所料,是用来执行逻辑判断的。 在这里,tag标签检查ordered_warranty值是否为True。如果是,模板系统将显示{% if ordered_warranty %}和{% else %}之间的内容;否则将显示{% else %}和{% endif %}之间的内容。{% else %}是可选的。

就是通俗一点说, {{xxx}}这个为变量。{% %} 为语法使用。在整体上模版的结构就是如此。

至此了解到模版的大致结构。现在了解一下模版标签。


标签

(一)if/else标签

只能判断True 和False 
{% if %} 标签会考察一个变量,如果这个变量为真(即,变量存在,非空,不是布尔值假),系统会显示在 {% if %} 和 {% endif %} 之间的任何内容,例如:

{% if today_is_weekend %}
    <p>Welcome to the weekend!p>
{% endif %}

{% else %} 标签是可选的:

{% if today_is_weekend %}
    <p>Welcome to the weekend!p>
{% else %}
    <p>Get back to work.p>
{% endif %}

{% if %} 标签接受 and , or 或者 not 关键字来对多个变量做判断 ,或者对变量取反( not ),但不允许在同一个标签中同时使用 and 和 or ,因为逻辑上可能模糊的。

(二)for标签

for标签用于迭代序列中的各个元素。 

与 Python 的 for 语句类似,语法是for X in Y。其中 Y 是要迭代的序列, X 是单次循环中使用的变量。每次迭代时,模板系统会渲染 {% for %} 和 {% endfor %} 之间的内容。

1.正向迭代

    {% for athlete in athlete_list %}
  • {{ athlete.name }}
  • {% endfor %}

2.加入reversed标签,反向迭代

{% for athlete in athlete_list reversed %} 
… 
{% endfor %}

3.对二元组解包

{% for x, y in points %}
    

There is a point at {{ x }},{{ y }}

{% endfor %}

4.字典解包

{% for key, value in data.items %}
    {{ key }}: {{ value }}
{% endfor %}

5.判断列表是否为空

在执行循环之前先检测列表的大小是一个通常的做法,当列表为空时输出一些特别的提示。

{% if athlete_list %}
    {% for athlete in athlete_list %}
        

{{ athlete.name }}

{% endfor %} {% else %}

There are no athletes. Only computer programmers.

{% endif %}

因为这种做法十分常见,所以for 标签支持一个可选的{% empty %} 分句,通过它,我们可以定义当列表为空时的输出内容。

{% for athlete in athlete_list %}
    

{{ athlete.name }}

{% empty %}

There are no athletes. Only computer programmers.

{% endfor %}

6. for标签内部模板变量forloop

在每个{% for %}循环里有一个称为forloop 的模板变量。 

  • forloop.counter 总是一个表示当前循环的执行次数的整数计数器。这个计数器是从1开始的,所以在第一次循环时 forloop.counter 将会被设置为1。 
{% for item in todo_list %}

{{ forloop.counter }}: {{ item }}

{% endfor %}
  • forloop.counter0 类似于 forloop.counter ,但是它是从0计数的。 第一次执行循环时这个变量会被设置为0。
  • forloop.revcounter的值是一个整数,表示循环中剩余的元素数量。第一次循环时, forloop.revcounter 的值是序列中要遍历的元素总数。最后一次循环时, forloop.revcounter的值为 1 。
  • forloop.revcounter0 与 forloop.revcounter类似,不过索引是基于零的。第一次循环时, forloop.revcounter0的值是序列中元素数量减去一。最后一次循环时, forloop.revcounter0 的值为 0 。
  • forloop.first 是个布尔值,第一次循环时为 True 。需要特殊处理第一个元素时很方便。
{% for object in objects %}
    {% if forloop.first %}
        
  • {% else %}
  • {% endif %} {{ object }}
  • {% endfor %}

    • forloop.last是个布尔值,最后一次循环时为True 。经常用它在一组链接之间放置管道符号(|)。
    {% for link in links %}
        {{ link }}{% if not forloop.last %} | {% endif %}
    {% endfor %}

    此外,还经常用它在一组单词之间放置逗号(,): 

    Favorite places:

    {% for p in places %} {{ p }}{% if not forloop.last %}, {% endif %} {% endfor %}
    • forloop.parentloop 是一个指向当前循环的上一级循环的 forloop 对象的引用(在嵌套循环的情况下)。
    {% for country in countries %}
        
        {% for city in country.city_list %}
            
        {% endfor %}
        
    Country #{{ forloop.parentloop.counter }} City #{{ forloop.counter }} {{ city }}
    {% endfor %}

    需要注意的是,

    forloop 变量只在循环内部可用。模板解析器遇到 {% endfor %} 时, forloop 随之消失。 

    如果有名为 forloop 的模板变量(不建议这么做),在 {% for %} 块中会重命名为 forloop.parentloop 。

    ifchanged
              使用形式:
              (a)如果直接检测循环变量是否变化,那么使用:
                  {% ifchanged %}  
                      (内容)
                  {% endifchanged %}
              (b)如果检测循环变量的某个dot变量,例如循环变量是date,那么检测date.hour,那么使用:
                  {% ifchanged date.hour%}  
                      (内容)
                  {% endifchanged %}    
              (c)ifchanged也可以加上一个{% else %}语句
              意义:检测本次循环的值和上一次循环的值一样不一样,只能用在循环里面。

    (三)ifequal / ifnotequal 标签

    对比两个值是否相对,ifequal相等,ifnotequal不相等。

    只有模板变量,字符串,整数和小数可以作为 {% ifequal %} 标签的参数。其他任何类型,例如Python的字典类型、列表类型、布尔类型,不能用在 {% ifequal %} 中。 

    下面的例子比较两个模板变量 user 和 currentuser :

    {% ifequal user currentuser %}
        

    Welcome!

    {% endifequal %}

    参数可以是硬编码的字符串,随便用单引号或者双引号引起来,所以下列代码都是正确的:

    {% ifequal section 'sitenews' %}
        

    Site News

    {% endifequal %}

    和 {% if %} 类似, {% ifequal %} 支持可选的 {% else%} 标签

    (四)一些常用标签

    (1)autoescape

    使用形式: 
    {% autoescape off %} 
    (内容) 
    {% endautoescape %} 
    意义:当某块内容不需要自动转义的时候,这样写就可以了。当然如果块内某些地方需要转义的话,调用filter也可以。

    (2)block

    使用形式: 
    {% block %} 
    (定义块内容) 
    {% endblock %} 
    意义:定义一个块,该块能够被继承他的子孙模板重写

    (3)comment

    使用形式: 
    {% comment %} 
    (内容) 
    {% endcomment %} 
    意义:模板系统会忽略该标签内部的所有内容。

    (4)cycle

    使用形式: 
    例如: 
    <\tr class=”{% cycle list%}”> 
    … 
    <\/tr> 
    意义:在循环时轮流使用给定的字符串列表中的值。

    (5)extends

    使用形式:{% extends “base.html” %}或者{% extends variable %}变量可以是一个字符串,也可以是一个模板对象。 
    意义:表示本模板要对指定的父模板进行扩展。

    (6)filter

    使用形式: 
    {%filter force_escape|lower%} 
    (内容) 
    {%endfilter%} 
    意义:将filter 标签圈定的内容执行过滤器操作。

    (7)firstof

    使用形式:{%firstof var1 var2 var3%} 
    意义:输出第一个值不等于False的变量 
    等价于: 
    {% if var1 %} 
    {{ var1 }} 
    {% else %} 
    {% if var2 %} 
    {{ var2 }} 
    {% else %} 
    {% if var3 %} 
    {{ var3 }} 
    {% endif %} 
    {% endif %} 
    {% endif %}

    (8)for

    使用形式: 
    {% for variable in list/dict %} 
    (使用variable) 
    {% endfor%} 
    意义:循环list中的每个值,进行相应的输出 
    注意:(a)也可以反向遍历{% for variable in list/dict reversed %} 
    (b)也可以{% for x, y in points %} points中的每个元素为 (x,y) 
    (c)也可以{% for key,value in data.items %} data是一个dictionary 
    for loop中定义的一些内建变量 
    forloop.counter 当前的迭代器数目(从1开始) 
    forloop.counter0 当前的迭代器数目(从0开始) 
    forloop.revcounter 当前的反向迭代器数目(从1开始) 
    forloop.revcounter0 当前的反向迭代器数目(从0开始) 
    forloop.first 值为True,如果是第一次通过迭代器 
    forloop.last 值为True,如果是最后一次通过迭代器 
    forloop.parentloop 对于嵌套循环,这是当前循环的上一层循环

    (9)for … empty

    使用形式如下: 
    {% for varibale in list %} 
    (内容1) 
    {% empty %} 
    (内容2) 
    {% endfor %} 
    意义:当list是空的时候,能够执行内容2,其形式等同于,先if判断list是否存在,然后在根据情况做什么操作。

    (10)if

    使用形式如下 : 
    {% if variable %} 
    (内容1) 
    {% else %} 
    (内容2) 
    {% endif %} 
    注意:variable中可以使用and or 或者not,但是有一条必须记住,就是不允许and 和 or一起使用

    (11)ifchanged

    使用形式: 
    (a)如果直接检测循环变量是否变化,那么使用: 
    {% ifchanged %} 
    (内容) 
    {% endifchanged %} 
    (b)如果检测循环变量的某个dot变量,例如循环变量是date,那么检测date.hour,那么使用: 
    {% ifchanged date.hour%} 
    (内容) 
    {% endifchanged %} 
    (c)ifchanged也可以加上一个{% else %}语句 
    意义:检测本次循环的值和上一次循环的值一样不一样,只能用在循环里面。

    (12)ifequal

    使用形式: 
    {% ifequal variable1 variable2 %} 
    … 
    {% endifequal %} 
    意义:判断两个变量是否相等。

    (13)ifnotequal

    使用与(12)相同

    (14)include

    使用形式:{% include “foo/bar.html” %}或者{% include template_name %} 
    意义:将另外一个模板文件中的内容添加到该文件中。注意区别extend是继承。

    (15)now

    使用形式:{% now “jS F Y H:i “%},注意存在需要转义的情况例如{% now “jS o\f F” %},因为f是格式化字符串

    具体的格式化字符串如下所示

    a ‘a.m.’ or ‘p.m.’ (Note that this is slightly different than PHP’s output, because this includes periods to match Associated Press style.) ‘a.m.’ 
    A ‘AM’ or ‘PM’. ‘AM’ 
    b Month, textual, 3 letters, lowercase. ‘jan’ 
    B Not implemented. 
    d Day of the month, 2 digits with leading zeros. ‘01’ to ‘31’ 
    D Day of the week, textual, 3 letters. ‘Fri’ 
    f Time, in 12-hour hours and minutes, with minutes left off if they’re zero. Proprietary extension. ‘1’, ‘1:30’ 
    F Month, textual, long. ‘January’ 
    g Hour, 12-hour format without leading zeros. ‘1’ to ‘12’ 
    G Hour, 24-hour format without leading zeros. ‘0’ to ‘23’ 
    h Hour, 12-hour format. ‘01’ to ‘12’ 
    H Hour, 24-hour format. ‘00’ to ‘23’ 
    i Minutes. ‘00’ to ‘59’ 
    I Not implemented. 
    j Day of the month without leading zeros. ‘1’ to ‘31’ 
    l Day of the week, textual, long. ‘Friday’ 
    L Boolean for whether it’s a leap year. True or False 
    m Month, 2 digits with leading zeros. ‘01’ to ‘12’ 
    M Month, textual, 3 letters. ‘Jan’ 
    n Month without leading zeros. ‘1’ to ‘12’ 
    N Month abbreviation in Associated Press style. Proprietary extension. ‘Jan.’, ‘Feb.’, ‘March’, ‘May’ 
    O Difference to Greenwich time in hours. ‘+0200’ 
    P Time, in 12-hour hours, minutes and ‘a.m.’/’p.m.’, with minutes left off if they’re zero and the special-case strings ‘midnight’ and ‘noon’ if appropriate. Proprietary extension. ‘1 a.m.’, ‘1:30 p.m.’, ‘midnight’, ‘noon’, ‘12:30 p.m.’ 
    r RFC 2822 formatted date. ‘Thu, 21 Dec 2000 16:01:07 +0200’ 
    s Seconds, 2 digits with leading zeros. ‘00’ to ‘59’ 
    S English ordinal suffix for day of the month, 2 characters. ‘st’, ‘nd’, ‘rd’ or ‘th’ 
    t Number of days in the given month. 28 to 31 
    T Time zone of this machine. ‘EST’, ‘MDT’ 
    U Not implemented. 
    w Day of the week, digits without leading zeros. ‘0’ (Sunday) to ‘6’ (Saturday) 
    W ISO-8601 week number of year, with weeks starting on Monday. 1, 53 
    y Year, 2 digits. ‘99’ 
    Y Year, 4 digits. ‘1999’ 
    z Day of the year. 0 to 365 
    Z Time zone offset in seconds. The offset for timezones west of UTC is always negative, and for those east of UTC is always positive.

    (16)spaceless

    使用形式:{% spaceless %} 
    (内容) 
    {% endspaceless %} 
    意义:删除包围内容中的所有tab或者回车字符。

    (17)template

    使用形式:{% templatetag %} 
    意义:模板系统本身没有转义的概念,因此如果要输出一个像“{%”这样的东东,就需要采用这种方式,否则就会语法错误 
    其参数有:

    openblock {% 
    closeblock %} 
    openvariable {{ 
    closevariable }} 
    openbrace { 
    closebrace } 
    opencomment {# 
    closecomment #}

    (18)with

    使用形式: 
    {% with “expensive var1” as var2 %} 
    {% endwith %} 
    意义:当一个变量的访问消耗很大的模板解析时,可以用另外一个变量替换它,这种替换只有在with内部有效。

    (19)url

    使用形式:{% url path.to.some_view arg1,arg2 %} 
    意义:给定某个module中函数的名字,给定参数,那么模板引擎给你一个URL,从而避免硬编码URL到代码中

    注意:前提是URLconf中存在相应的映射,如果URLconf中没有该映射,那么会抛出异常, 
    这是可以选择使用 
    {% url path.to.view arg1 ,arg2 as the_url %} 
    <\a href=”{{ the_url }}”>Link to optional stuff \<\/\a> 
    其实这相当于 
    {% url path.to.view as the_url %} 
    {% if the_url %} 
    Link to optional stuff  
    {% endif %}

    csrf_token

    这个标签用于跨站请求伪造保护。

    在页面的form表单里面写上{% csrf_token %}


    过滤器

    通过过滤器可以改变变量的显示方式,过滤器的形式是:{{ variable | filter }},管道符号'|'代表使用过滤器。

    例如:

    {{value|default:"nohting"}}

    表示当value为空或None时就会显示”nothing“。

    Django中有几十个内建的过滤器。

    先看过滤器的使用说明:

    1.过滤器能够采用链式的方式使用

    例如:

    {{ text | escape | linebreaks }}

    2.过滤器可以带参数

    例如:

    {{ bio|truncatewords:30 }}

    如果参数中带有空格,那么需要用引号引起来,例如:

    {{ list | join : ", "}}

    下面是常用的Django内建过滤器:

    (1)add

    例如:

    {{ value | add: "2"}}

    意义:把value的值增加2。比如,value的值是4,那么输出为6。注意,add首先尝试把两个值当作整数相加,如果失败,就尝试把两个值组合在一起(比如遇到字符串或list的时候),其他失败的情况返回一个空字符串。

    例如:

    {{first|add:second}},first=[1,2,3],second=[4,5,6]

    输出结果为[1,2,3,4,5,6]。(小白我一开始以为是[5,7,9]。。。。。)

    (2)addslashes

    {{ value | addslashes }} 

    意义:在value中引号(单引号和双引号)前增加反斜线

    例如:

    {{value|addslashes}},value=I'm using Django

    输出结果为I\'m using Django

    (3)capfirst

    {{ value | capfirst }} 

    意义:value的第一个字符转化成大写形式

    (4)cut

    {{ value | cut:arg}} 

    意义:移出value中包含arg的字符串。如果value是"String with spaces",arg是" ",那么输出结果是"Stringwithspaces"

    (5)date

    意义:将日期格式数据按照给定的格式输出。

    {{ value | date:"D d M Y" }}

    如果value是一个datetime对象,那么输出将是字符串"Wed 09 Jan 2008"。

    下面的例子没有格式化字符串,这时候格式化字符串会自动采用DATE_FORMAT所设置的形式。

     {{ value | date }}

    (6)default

    意义:如果value的意义是False,那么输出使用缺省值。

    {{ value | default: "nothing" }}

    如果value是"",输出将是"nothing"。

    (7)default_if_none

    {{ value | default_if_none:"nothing" }}

    意义:如果value是None,那么输出将使用缺省值(这里是"nothing")

    (8)dictsort

    {{ value | dictsort:"name"}}

    意义:如果value的值是一个字典,那么返回值是按照关键字排序的结果。

    例如,如果value是 [ {'name': 'zed', 'age': 19}, {'name': 'amy', 'age': 22}, {'name': 'joe', 'age': 31}, ] 那么,输出是: [ {'name': 'amy', 'age': 22}, {'name': 'joe', 'age': 31}, {'name': 'zed', 'age': 19}, ]

    (9)dictsortreversed

    意义:如果value的值是一个字典,那么返回值是按照关键字排序的结果的反序。

    使用形式与上述(8)完全相同。

    (10)divisibleby

    {{ value | divisibleby:arg}}

    意义:如果value能够被arg整除,那么返回值将是True

    例如value是21,arg是3,那么输出将是True

    (11)escape

    {{ value | escape}} 

    意义:替换value中的某些字符,以适应HTML格式,包括:

    < 会被转换为 <

    > 会被转换位 >

    '(单引号)会被转换为 '

    " (双引号)会被转换为 "

    & 会被转换为 &

    注意:escape仅仅在输出的时候才起作用,所以escape不能够用在链式过滤器的中间,它总是最后一个过滤器。如果想在链式过滤器的中间使用,那么可以使用force_escape。

    (12)escapejs

    {{ value | escapejs }}

    意义:替换value中的某些字符,以适应JavaScript和Json格式

    (13)filesizeformat

    {{ value | filesizeformat }}

    意义:格式化value,使其成为易读的文件大小

    (14)first

    {{ value | first }}

    意义:返回列表中的第一个Item

    如果value是列表['a','b','c'],那么输出将是'a'

    (15)floatformat

    {{ value | floatformat}}或者{{value|floatformat:arg}}

    arg可以是正数,也可以是负数。没有参数的floatformat相当于floatformat:-1

    • 如果不带arg,那么引擎会四舍五入,同时最多只保留一位小数

    1. 34.23234    {{ value|floatformat }}  34.2  
    2. 34.00000    {{ value|floatformat }} 34  
    3. 34.26000    {{ value|floatformat }} 34.3  
    • 如果arg是正数,那么引擎会四舍五入,同时保留arg个位的小数

    1. 34.23234    {{ value|floatformat:3 }}   34.232  
    2. 34.00000    {{ value|floatformat:3 }}   34.000  
    3. 34.26000    {{ value|floatformat:3 }}   34.260 
    • 如果arg是负数,那么引擎会四舍五入,如果有小数部分,那么保留arg个位的小数,否则没有任何小数部分

    1. 34.23234    {{ value|floatformat:"-3" }}    34.232  
    2. 34.00000    {{ value|floatformat:"-3" }}    34  
    3. 34.26000    {{ value|floatformat:"-3" }}    34.26  


    (16)get_digit 

    使用形式:{{ value | get_digit:"arg"}}

    例如,如果value是123456789,arg是2,那么输出是8 

    意义:给定一个数字,返回,请求的数字,记住:1代表最右边的数字,如果value不是合法输入,那么会返回所有原有值。



    (17)iriencode 

    使用形式:{{value | iriencode}} 

    意义:如果value中有非ASCII字符,那么将其进行转化成URL中适合的编码,如果value已经进行过URLENCODE,该操作就不会再起作用。



    (18)join 

    使用形式:{{ value | join:"arg"}}

    如果value是['a','b','c'],arg是'//'

    那么输出是a//b//c 

    意义:使用指定的字符串连接一个list,作用如同python的str.join(list)



    19. last 

    使用形式:{{ value | last }} 

    意义:返回列表中的最后一个Item



    20. length 

    使用形式:{{ value | length }} 

    意义:返回value的长度。


    21. length_is 

    使用形式:{{ value | length_is:"arg"}} 

    意义:返回True,如果value的长度等于arg的时候

    例如:如果value是['a','b','c'],arg是3,那么返回True



    22. linebreaks 

    使用形式:{{value|linebreaks}} 

    意义:value中的"\n"将被替代,并且整个value使用

    (注意这里是个换行!!!!)包围起来,从而适和HTML的格式

    23. linebreaksbr

     使用形式:{{value |linebreaksbr}} 

    意义:value中的"\n"将被
    替代



    24. linenumbers 

    使用形式:{{value | linenumbers}} 

    意义:显示的文本,带有行数。



    25. ljust

     使用形式:{{value | ljust}} 

    意义:在一个给定宽度的字段中,左对齐显示value



    26. center

     使用形式:{{value | center}}

     意义:在一个给定宽度的字段中,中心对齐显示value



    27. rjust 

    使用形式:{{value | rjust}} 

    意义:在一个给定宽度的字段中,右对齐显示value



    28. lower 

    使用形式:{{value | lower}} 

    意义:将一个字符串转换成小写形式



    29. make_list 

    使用形式:{{value | make_list}} 

    意义:将value转换成一个list,对于字符串,转换成字符list;对于整数,转换成整数list 

    例如value是Joel,那么输出将是[u'J',u'o',u'e',u'l'];value是123,那么输出将是[1,2,3]



    30. pluralize 

    使用形式:{{value | pluralize}},或者{{value | pluralize:"es"}},或者{{value | pluralize:"y,ies"}} 

    意义:如果value不是1,则返回一个复数后缀,缺省的后缀是's'



    31. random 

    使用形式:{{value | random}} 

    意义:从给定的list中返回一个任意的Item



    32. removetags 

    使用形式:{{value | removetags:"tag1 tag2 tag3..."}} 

    意义:删除value中tag1,tag2....的标签。

    例如,如果value是

                    Joel a slug 

                    tags是"b span",

    那么输出将是:Joel a slug



    33. safe

     使用形式:{{value | safe}} 

    意义:当系统设置autoescaping打开的时候,该过滤器使得输出不进行escape转换



    34. safeseq 

    与上述safe基本相同,但有一点不同的就是:safe是针对字符串,而safeseq是针对多个字符串组成的sequence


    35. slice

     使用形式:{{some_list | slice:":2"}} 

    意义:与python语法中的slice相同,:2表示第一的第二个元素



    36. slugify 

    使用形式:{{value | slugify}} 

    意义:将value转换成小写形式,同事删除所有分单词字符,并将空格变成横线 

    例如:如果value是Joel is a slug,那么输出将是joel-is-a-slug



    37. stringformat 

    这个不经常用,先不说 

    简单举个例子:如果value是 10,那么输出 1.000000E+01



    38. striptags 

    使用形式:{{value | striptags}} 

    意义:删除value中的所有HTML标签



    39. time 

    使用形式:{{value | time:"H:i"}}或者{{value | time}} 

    意义:格式化时间输出,如果time后面没有格式化参数,那么输出按照TIME_FORMAT中设置的进行。



    40. title 

    转换一个字符串成为title格式。 如: value是 "my first post",输出: "My First Post"



    41. truncatewords 

    使用形式:{{value | truncatewords:2}} 

    意义:将value切成truncatewords指定的单词数目 

    例如,如果value是Joel is a slug 那么输出将是:Joel is ...



    42. truncatewords_html 

    使用形式同(39) 

    意义:truncation点之前如果某个标签打开了,但是没有关闭,那么在truncation点会立即关闭。 因为这个操作的效率比truncatewords低,所有只有在value是html格式时,才考虑使用。



    43. upper 

    转换一个字符串为大写形式



    44. urlencode 

    将一个字符串进行URLEncode



    45. urlize 

    意义:将一个字符串中的URL转化成可点击的形式。 

    使用形式:{{ value | urlize }} 

    例如,如果value是Check out www.djangoproject.com,那么输出将是: Check out www.djangoproject.com



    46. urlizetrunc 

    使用形式:{{ value | urlizetrunc:15}} 

    意义:与(43)相同,但是有一点不同就是现实的链接字符会被truncate成特定的长度,后面以...现实。



    47. wordcount

     返回字符串中单词的数目



    48. wordwrap 

    使用形式:{{value | wordwrap:5}} 

    意义:按照指定的长度包装字符串 

    例如,如果value是Joel is a slug,那么输出将会是: Joel is a slug



    49. timesince 

    使用形式:{{value | timesince:arg}} 

    意义:返回参数arg到value的天数和小时数 

    例如,如果 blog_date 是一个日期实例,表示 2006-06-01 午夜, 而 comment_date 是一个日期实例,表示 2006-06-01 早上8点, 那么 {{ comment_date|timesince:blog_date }} 将返回 "8 hours".



    50. timeuntil 

    使用形式:{{value | timeuntil}} 

    意义:与(47)基本相同,一个不同点就是,返回的是value距离当前日期的天数和小时数。


    注释写法

    1
    { # ... #}


    Django 模板概念和运用

    母板

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    = "en" >
       = "UTF-8" >
       - equiv = "x-ua-compatible"  content = "IE=edge" >
       = "viewport"  content = "width=device-width, initial-scale=1" >
       Title<</code> <code class="python keyword" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,255);">/</code> <code class="python plain" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,0);">title></code> </div> <div class="line number8 index7 alt1" style="margin:0px;padding:0px 1em;background-image:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;min-height:auto;white-space:nowrap;"> <code class="python spaces" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;">  </code> <code class="python plain" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,0);">{</code> <code class="python keyword" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,255);">%</code>  <code class="python plain" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,0);">block page</code> <code class="python keyword" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,255);">-</code> <code class="python plain" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,0);">css </code> <code class="python keyword" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,255);">%</code> <code class="python plain" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,0);">}</code> </div> <div class="line number9 index8 alt2" style="margin:0px;padding:0px 1em;background:rgb(244,244,244) none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;min-height:auto;white-space:nowrap;"> <code class="python spaces" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;">  </code>  </div> <div class="line number10 index9 alt1" style="margin:0px;padding:0px 1em;background-image:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;min-height:auto;white-space:nowrap;"> <code class="python spaces" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;">  </code> <code class="python plain" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,0);">{</code> <code class="python keyword" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,255);">%</code>  <code class="python plain" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,0);">endblock </code> <code class="python keyword" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,255);">%</code> <code class="python plain" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,0);">}</code> </div> <div class="line number11 index10 alt2" style="margin:0px;padding:0px 1em;background:rgb(244,244,244) none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;min-height:auto;white-space:nowrap;"> <code class="python plain" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,0);"><</code> <code class="python keyword" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,255);">/</code> <code class="python plain" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,0);">head></code> </div> <div class="line number12 index11 alt1" style="margin:0px;padding:0px 1em;background-image:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;min-height:auto;white-space:nowrap;"> <code class="python plain" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,0);"><body></code> </div> <div class="line number13 index12 alt2" style="margin:0px;padding:0px 1em;background:rgb(244,244,244) none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;min-height:auto;white-space:nowrap;">   </div> <div class="line number14 index13 alt1" style="margin:0px;padding:0px 1em;background-image:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;min-height:auto;white-space:nowrap;"> <code class="python plain" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,0);"><h1>这是母板的标题<</code> <code class="python keyword" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,255);">/</code> <code class="python plain" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,0);">h1></code> </div> <div class="line number15 index14 alt2" style="margin:0px;padding:0px 1em;background:rgb(244,244,244) none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;min-height:auto;white-space:nowrap;">   </div> <div class="line number16 index15 alt1" style="margin:0px;padding:0px 1em;background-image:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;min-height:auto;white-space:nowrap;"> <code class="python plain" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,0);">{</code> <code class="python keyword" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,255);">%</code>  <code class="python plain" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,0);">block page</code> <code class="python keyword" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,255);">-</code> <code class="python plain" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,0);">main </code> <code class="python keyword" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,255);">%</code> <code class="python plain" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,0);">}</code> </div> <div class="line number17 index16 alt2" style="margin:0px;padding:0px 1em;background:rgb(244,244,244) none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;min-height:auto;white-space:nowrap;">   </div> <div class="line number18 index17 alt1" style="margin:0px;padding:0px 1em;background-image:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;min-height:auto;white-space:nowrap;"> <code class="python plain" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,0);">{</code> <code class="python keyword" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,255);">%</code>  <code class="python plain" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,0);">endblock </code> <code class="python keyword" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,255);">%</code> <code class="python plain" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,0);">}</code> </div> <div class="line number19 index18 alt2" style="margin:0px;padding:0px 1em;background:rgb(244,244,244) none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;min-height:auto;white-space:nowrap;"> <code class="python plain" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,0);"><h1>母板底部内容<</code> <code class="python keyword" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,255);">/</code> <code class="python plain" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,0);">h1></code> </div> <div class="line number20 index19 alt1" style="margin:0px;padding:0px 1em;background-image:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;min-height:auto;white-space:nowrap;"> <code class="python plain" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,0);">{</code> <code class="python keyword" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,255);">%</code>  <code class="python plain" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,0);">block page</code> <code class="python keyword" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,255);">-</code> <code class="python plain" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,0);">js </code> <code class="python keyword" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,255);">%</code> <code class="python plain" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,0);">}</code> </div> <div class="line number21 index20 alt2" style="margin:0px;padding:0px 1em;background:rgb(244,244,244) none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;min-height:auto;white-space:nowrap;">   </div> <div class="line number22 index21 alt1" style="margin:0px;padding:0px 1em;background-image:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;min-height:auto;white-space:nowrap;"> <code class="python plain" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,0);">{</code> <code class="python keyword" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,255);">%</code>  <code class="python plain" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,0);">endblock </code> <code class="python keyword" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,255);">%</code> <code class="python plain" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,0);">}</code> </div> <div class="line number23 index22 alt2" style="margin:0px;padding:0px 1em;background:rgb(244,244,244) none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;min-height:auto;white-space:nowrap;"> <code class="python plain" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,0);"><</code> <code class="python keyword" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,255);">/</code> <code class="python plain" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,0);">body></code> </div> <div class="line number24 index23 alt1" style="margin:0px;padding:0px 1em;background-image:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;min-height:auto;white-space:nowrap;"> <code class="python plain" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,0);"><</code> <code class="python keyword" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,255);">/</code> <code class="python plain" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,0);">html></code> </div> </div></td> </tr> </tbody> </table> </div> </div> </div> <p style="margin:10px auto;color:rgb(51,51,51);font-family:Verdana, Arial, Helvetica, sans-serif;font-size:14px;background-color:rgb(255,255,255);">  </p> <p style="margin:10px auto;color:rgb(51,51,51);font-family:Verdana, Arial, Helvetica, sans-serif;background-color:rgb(255,255,255);"><span style="font-size:16px;">注意:我们通常会在母板中定义页面专用的CSS块和JS块,方便子页面替换。</span></p> <h2 style="margin-top:20px;margin-bottom:20px;padding:0px;line-height:1.5;color:rgb(51,51,51);font-family:Verdana, Arial, Helvetica, sans-serif;background-color:rgb(255,255,255);"><span style="font-size:18px;">继承母板</span></h2> <p style="margin:10px auto;color:rgb(51,51,51);font-family:Verdana, Arial, Helvetica, sans-serif;background-color:rgb(255,255,255);"><span style="font-size:16px;">在子页面中在页面最上方使用下面的语法来继承母板。</span></p> <div class="cnblogs_Highlighter sh-gutter" style="margin:0px;padding:0px;color:rgb(51,51,51);font-family:Verdana, Arial, Helvetica, sans-serif;font-size:14px;background-color:rgb(255,255,255);"> <div style="margin:0px;padding:0px;"> <div class="syntaxhighlighter python" style="padding:0px;width:806px;margin:1em 0px;font-size:1em;"> <table border="0" style="border-spacing:0px;max-width:850px;border:1px solid #C0C0C0;width:806px;margin:0px;padding:0px;background:none;float:none;height:auto;line-height:1.1em;vertical-align:baseline;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;font-size:12px;min-height:auto;"> <tbody style="margin:0px;padding:0px;background:none;float:none;height:auto;line-height:1.1em;vertical-align:baseline;width:auto;min-height:auto;"> <tr style="margin:0px;padding:0px;background:none;border-top:0px;float:none;height:auto;line-height:1.1em;vertical-align:baseline;width:auto;min-height:auto;"> <td class="gutter" style="padding:3px;border-color:#C0C0C0;border-collapse:collapse;margin:0px;background:none;float:none;height:auto;line-height:1.1em;vertical-align:baseline;width:35px;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;font-size:12px;min-height:auto;color:rgb(175,175,175);"> <div class="line number1 index0 alt2" style="margin:0px;padding:0px .5em;background:rgb(244,244,244) none;border-width:0px 2px 0px 0px;border-right-style:solid;border-right-color:rgb(108,226,108);float:none;height:auto;line-height:1.8em;text-align:right;vertical-align:baseline;width:auto;min-height:auto;white-space:nowrap;"> 1 </div></td> <td class="code" style="padding:3px;border-color:#C0C0C0;border-collapse:collapse;margin:0px;background:none;float:none;height:auto;line-height:1.1em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;font-size:12px;min-height:auto;"> <div class="container" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.1em;vertical-align:baseline;width:auto;min-height:auto;"> <div class="line number1 index0 alt2" style="margin:0px;padding:0px 1em;background:rgb(244,244,244) none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;min-height:auto;white-space:nowrap;"> <code class="python plain" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,0);">{</code> <code class="python keyword" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,255);">%</code>  <code class="python plain" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,0);">extends </code> <code class="python string" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:#0000FF;">'layouts.html'</code>  <code class="python keyword" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,255);">%</code> <code class="python plain" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,0);">}</code> </div> </div></td> </tr> </tbody> </table> </div> </div> </div> <h2 style="margin-top:20px;margin-bottom:20px;padding:0px;line-height:1.5;color:rgb(51,51,51);font-family:Verdana, Arial, Helvetica, sans-serif;background-color:rgb(255,255,255);"><span style="font-size:18px;">块(block)</span></h2> <p style="margin:10px auto;"><span style="font-size:16px;color:rgb(51,51,51);font-family:Verdana, Arial, Helvetica, sans-serif;background-color:rgb(255,255,255);">通过在母板中使用{%block xxx%}</span><span><span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:16px;color:#333333;"><span style="background-color:rgb(255,255,255);">来定义"块"。</span></span></span></p> <p style="margin:10px auto;color:rgb(51,51,51);font-family:Verdana, Arial, Helvetica, sans-serif;background-color:rgb(255,255,255);"><span style="font-size:16px;">在子页面中通过定义母板中的block名来对应替换母板中相应的内容。</span></p> <div class="cnblogs_Highlighter sh-gutter" style="margin:0px;padding:0px;color:rgb(51,51,51);font-family:Verdana, Arial, Helvetica, sans-serif;font-size:14px;background-color:rgb(255,255,255);"> <div style="margin:0px;padding:0px;"> <div class="syntaxhighlighter python" style="padding:0px;width:806px;margin:1em 0px;font-size:1em;"> <table border="0" style="border-spacing:0px;max-width:850px;border:1px solid #C0C0C0;width:806px;margin:0px;padding:0px;background:none;float:none;height:auto;line-height:1.1em;vertical-align:baseline;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;font-size:12px;min-height:auto;"> <tbody style="margin:0px;padding:0px;background:none;float:none;height:auto;line-height:1.1em;vertical-align:baseline;width:auto;min-height:auto;"> <tr style="margin:0px;padding:0px;background:none;border-top:0px;float:none;height:auto;line-height:1.1em;vertical-align:baseline;width:auto;min-height:auto;"> <td class="gutter" style="padding:3px;border-color:#C0C0C0;border-collapse:collapse;margin:0px;background:none;float:none;height:auto;line-height:1.1em;vertical-align:baseline;width:35px;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;font-size:12px;min-height:auto;color:rgb(175,175,175);"> <div class="line number1 index0 alt2" style="margin:0px;padding:0px .5em;background:rgb(244,244,244) none;border-width:0px 2px 0px 0px;border-right-style:solid;border-right-color:rgb(108,226,108);float:none;height:auto;line-height:1.8em;text-align:right;vertical-align:baseline;width:auto;min-height:auto;white-space:nowrap;"> 1 </div> <div class="line number2 index1 alt1" style="margin:0px;padding:0px .5em;background-image:none;border-width:0px 2px 0px 0px;border-right-style:solid;border-right-color:rgb(108,226,108);float:none;height:auto;line-height:1.8em;text-align:right;vertical-align:baseline;width:auto;min-height:auto;white-space:nowrap;"> 2 </div> <div class="line number3 index2 alt2" style="margin:0px;padding:0px .5em;background:rgb(244,244,244) none;border-width:0px 2px 0px 0px;border-right-style:solid;border-right-color:rgb(108,226,108);float:none;height:auto;line-height:1.8em;text-align:right;vertical-align:baseline;width:auto;min-height:auto;white-space:nowrap;"> 3 </div> <div class="line number4 index3 alt1" style="margin:0px;padding:0px .5em;background-image:none;border-width:0px 2px 0px 0px;border-right-style:solid;border-right-color:rgb(108,226,108);float:none;height:auto;line-height:1.8em;text-align:right;vertical-align:baseline;width:auto;min-height:auto;white-space:nowrap;"> 4 </div> <div class="line number5 index4 alt2" style="margin:0px;padding:0px .5em;background:rgb(244,244,244) none;border-width:0px 2px 0px 0px;border-right-style:solid;border-right-color:rgb(108,226,108);float:none;height:auto;line-height:1.8em;text-align:right;vertical-align:baseline;width:auto;min-height:auto;white-space:nowrap;"> 5 </div></td> <td class="code" style="padding:3px;border-color:#C0C0C0;border-collapse:collapse;margin:0px;background:none;float:none;height:auto;line-height:1.1em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;font-size:12px;min-height:auto;"> <div class="container" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.1em;vertical-align:baseline;width:auto;min-height:auto;"> <div class="line number1 index0 alt2" style="margin:0px;padding:0px 1em;background:rgb(244,244,244) none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;min-height:auto;white-space:nowrap;"> <code class="python plain" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,0);">{</code> <code class="python keyword" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,255);">%</code>  <code class="python plain" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,0);">block page</code> <code class="python keyword" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,255);">-</code> <code class="python plain" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,0);">main </code> <code class="python keyword" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,255);">%</code> <code class="python plain" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,0);">}</code> </div> <div class="line number2 index1 alt1" style="margin:0px;padding:0px 1em;background-image:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;min-height:auto;white-space:nowrap;"> <code class="python spaces" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;">  </code> <code class="python plain" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,0);"><p>世情薄<</code> <code class="python keyword" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,255);">/</code> <code class="python plain" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,0);">p></code> </div> <div class="line number3 index2 alt2" style="margin:0px;padding:0px 1em;background:rgb(244,244,244) none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;min-height:auto;white-space:nowrap;"> <code class="python spaces" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;">  </code> <code class="python plain" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,0);"><p>人情恶<</code> <code class="python keyword" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,255);">/</code> <code class="python plain" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,0);">p></code> </div> <div class="line number4 index3 alt1" style="margin:0px;padding:0px 1em;background-image:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;min-height:auto;white-space:nowrap;"> <code class="python spaces" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;">  </code> <code class="python plain" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,0);"><p>雨送黄昏花易落<</code> <code class="python keyword" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,255);">/</code> <code class="python plain" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,0);">p></code> </div> <div class="line number5 index4 alt2" style="margin:0px;padding:0px 1em;background:rgb(244,244,244) none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;min-height:auto;white-space:nowrap;"> <code class="python plain" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,0);">{</code> <code class="python keyword" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,255);">%</code>  <code class="python plain" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,0);">endblock </code> <code class="python keyword" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,255);">%</code> <code class="python plain" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,0);">}</code> </div> </div></td> </tr> </tbody> </table> </div> </div> </div> <h2 style="margin-top:20px;margin-bottom:20px;padding:0px;line-height:1.5;color:rgb(51,51,51);font-family:Verdana, Arial, Helvetica, sans-serif;background-color:rgb(255,255,255);"><span style="font-size:18px;">组件</span></h2> <p style="margin:10px auto;color:rgb(51,51,51);font-family:Verdana, Arial, Helvetica, sans-serif;background-color:rgb(255,255,255);"><span style="font-size:16px;">可以将常用的页面内容如导航条,页尾信息等组件保存在单独的文件中,然后在需要使用的地方按如下语法导入即可。</span></p> <div class="cnblogs_Highlighter sh-gutter" style="margin:0px;padding:0px;color:rgb(51,51,51);font-family:Verdana, Arial, Helvetica, sans-serif;font-size:14px;background-color:rgb(255,255,255);"> <div style="margin:0px;padding:0px;"> <div class="syntaxhighlighter python" style="padding:0px;width:806px;margin:1em 0px;font-size:1em;"> <table border="0" style="border-spacing:0px;max-width:850px;border:1px solid #C0C0C0;width:806px;margin:0px;padding:0px;background:none;float:none;height:auto;line-height:1.1em;vertical-align:baseline;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;font-size:12px;min-height:auto;"> <tbody style="margin:0px;padding:0px;background:none;float:none;height:auto;line-height:1.1em;vertical-align:baseline;width:auto;min-height:auto;"> <tr style="margin:0px;padding:0px;background:none;border-top:0px;float:none;height:auto;line-height:1.1em;vertical-align:baseline;width:auto;min-height:auto;"> <td class="gutter" style="padding:3px;border-color:#C0C0C0;border-collapse:collapse;margin:0px;background:none;float:none;height:auto;line-height:1.1em;vertical-align:baseline;width:35px;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;font-size:12px;min-height:auto;color:rgb(175,175,175);"> <div class="line number1 index0 alt2" style="margin:0px;padding:0px .5em;background:rgb(244,244,244) none;border-width:0px 2px 0px 0px;border-right-style:solid;border-right-color:rgb(108,226,108);float:none;height:auto;line-height:1.8em;text-align:right;vertical-align:baseline;width:auto;min-height:auto;white-space:nowrap;"> 1 </div></td> <td class="code" style="padding:3px;border-color:#C0C0C0;border-collapse:collapse;margin:0px;background:none;float:none;height:auto;line-height:1.1em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;font-size:12px;min-height:auto;"> <div class="container" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.1em;vertical-align:baseline;width:auto;min-height:auto;"> <div class="line number1 index0 alt2" style="margin:0px;padding:0px 1em;background:rgb(244,244,244) none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;min-height:auto;white-space:nowrap;"> <code class="python plain" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,0);">{</code> <code class="python keyword" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,255);">%</code>  <code class="python plain" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,0);">include </code> <code class="python string" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:#0000FF;">'navbar.html'</code>  <code class="python keyword" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,255);">%</code> <code class="python plain" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,0);">}</code> </div> </div></td> </tr> </tbody> </table> </div> </div> </div> <h2 style="margin-top:20px;margin-bottom:20px;padding:0px;line-height:1.5;color:rgb(51,51,51);font-family:Verdana, Arial, Helvetica, sans-serif;background-color:rgb(255,255,255);"><span style="font-size:18px;">静态文件相关</span></h2> <div class="cnblogs_Highlighter sh-gutter" style="margin:0px;padding:0px;color:rgb(51,51,51);font-family:Verdana, Arial, Helvetica, sans-serif;font-size:14px;background-color:rgb(255,255,255);"> <div style="margin:0px;padding:0px;"> <div class="syntaxhighlighter python" style="padding:0px;width:806px;margin:1em 0px;font-size:1em;"> <table border="0" style="border-spacing:0px;max-width:850px;border:1px solid #C0C0C0;width:806px;margin:0px;padding:0px;background:none;float:none;height:auto;line-height:1.1em;vertical-align:baseline;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;font-size:12px;min-height:auto;"> <tbody style="margin:0px;padding:0px;background:none;float:none;height:auto;line-height:1.1em;vertical-align:baseline;width:auto;min-height:auto;"> <tr style="margin:0px;padding:0px;background:none;border-top:0px;float:none;height:auto;line-height:1.1em;vertical-align:baseline;width:auto;min-height:auto;"> <td class="gutter" style="padding:3px;border-color:#C0C0C0;border-collapse:collapse;margin:0px;background:none;float:none;height:auto;line-height:1.1em;vertical-align:baseline;width:35px;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;font-size:12px;min-height:auto;color:rgb(175,175,175);"> <div class="line number1 index0 alt2" style="margin:0px;padding:0px .5em;background:rgb(244,244,244) none;border-width:0px 2px 0px 0px;border-right-style:solid;border-right-color:rgb(108,226,108);float:none;height:auto;line-height:1.8em;text-align:right;vertical-align:baseline;width:auto;min-height:auto;white-space:nowrap;"> 1 </div> <div class="line number2 index1 alt1" style="margin:0px;padding:0px .5em;background-image:none;border-width:0px 2px 0px 0px;border-right-style:solid;border-right-color:rgb(108,226,108);float:none;height:auto;line-height:1.8em;text-align:right;vertical-align:baseline;width:auto;min-height:auto;white-space:nowrap;"> 2 </div></td> <td class="code" style="padding:3px;border-color:#C0C0C0;border-collapse:collapse;margin:0px;background:none;float:none;height:auto;line-height:1.1em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;font-size:12px;min-height:auto;"> <div class="container" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.1em;vertical-align:baseline;width:auto;min-height:auto;"> <div class="line number1 index0 alt2" style="margin:0px;padding:0px 1em;background:rgb(244,244,244) none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;min-height:auto;white-space:nowrap;"> <code class="python plain" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,0);">{</code> <code class="python keyword" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,255);">%</code>  <code class="python plain" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,0);">load static </code> <code class="python keyword" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,255);">%</code> <code class="python plain" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,0);">}</code> </div> <div class="line number2 index1 alt1" style="margin:0px;padding:0px 1em;background-image:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;min-height:auto;white-space:nowrap;"> <code class="python plain" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,0);"><img src</code> <code class="python keyword" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,255);">=</code> <code class="python string" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:#0000FF;">"{% static "</code> <code class="python plain" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,0);">images</code> <code class="python keyword" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,255);">/</code> <code class="python plain" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,0);">hi.jpg</code> <code class="python string" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:#0000FF;">" %}"</code>  <code class="python plain" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,0);">alt</code> <code class="python keyword" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,255);">=</code> <code class="python string" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:#0000FF;">"Hi!"</code>  <code class="python keyword" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,255);">/</code> <code class="python plain" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,0);">></code> </div> </div></td> </tr> </tbody> </table> </div> </div> </div> <p style="margin:10px auto;color:rgb(51,51,51);font-family:Verdana, Arial, Helvetica, sans-serif;background-color:rgb(255,255,255);"><span style="font-size:16px;">引用JS文件时使用:</span></p> <div class="cnblogs_Highlighter sh-gutter" style="margin:0px;padding:0px;color:rgb(51,51,51);font-family:Verdana, Arial, Helvetica, sans-serif;font-size:14px;background-color:rgb(255,255,255);"> <div style="margin:0px;padding:0px;"> <div class="syntaxhighlighter python" style="padding:0px;width:806px;margin:1em 0px;font-size:1em;"> <table border="0" style="border-spacing:0px;max-width:850px;border:1px solid #C0C0C0;width:806px;margin:0px;padding:0px;background:none;float:none;height:auto;line-height:1.1em;vertical-align:baseline;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;font-size:12px;min-height:auto;"> <tbody style="margin:0px;padding:0px;background:none;float:none;height:auto;line-height:1.1em;vertical-align:baseline;width:auto;min-height:auto;"> <tr style="margin:0px;padding:0px;background:none;border-top:0px;float:none;height:auto;line-height:1.1em;vertical-align:baseline;width:auto;min-height:auto;"> <td class="gutter" style="padding:3px;border-color:#C0C0C0;border-collapse:collapse;margin:0px;background:none;float:none;height:auto;line-height:1.1em;vertical-align:baseline;width:35px;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;font-size:12px;min-height:auto;color:rgb(175,175,175);"> <div class="line number1 index0 alt2" style="margin:0px;padding:0px .5em;background:rgb(244,244,244) none;border-width:0px 2px 0px 0px;border-right-style:solid;border-right-color:rgb(108,226,108);float:none;height:auto;line-height:1.8em;text-align:right;vertical-align:baseline;width:auto;min-height:auto;white-space:nowrap;"> 1 </div> <div class="line number2 index1 alt1" style="margin:0px;padding:0px .5em;background-image:none;border-width:0px 2px 0px 0px;border-right-style:solid;border-right-color:rgb(108,226,108);float:none;height:auto;line-height:1.8em;text-align:right;vertical-align:baseline;width:auto;min-height:auto;white-space:nowrap;"> 2 </div></td> <td class="code" style="padding:3px;border-color:#C0C0C0;border-collapse:collapse;margin:0px;background:none;float:none;height:auto;line-height:1.1em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;font-size:12px;min-height:auto;"> <div class="container" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.1em;vertical-align:baseline;width:auto;min-height:auto;"> <div class="line number1 index0 alt2" style="margin:0px;padding:0px 1em;background:rgb(244,244,244) none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;min-height:auto;white-space:nowrap;"> <code class="python plain" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,0);">{</code> <code class="python keyword" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,255);">%</code>  <code class="python plain" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,0);">load static </code> <code class="python keyword" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,255);">%</code> <code class="python plain" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,0);">}</code> </div> <div class="line number2 index1 alt1" style="margin:0px;padding:0px 1em;background-image:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;min-height:auto;white-space:nowrap;"> <code class="python plain" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,0);"><script src</code> <code class="python keyword" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,255);">=</code> <code class="python string" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:#0000FF;">"{% static "</code> <code class="python plain" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,0);">mytest.js</code> <code class="python string" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:#0000FF;">" %}"</code> <code class="python plain" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,0);">><</code> <code class="python keyword" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,255);">/</code> <code class="python plain" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,0);">script></code> </div> </div></td> </tr> </tbody> </table> </div> </div> </div> <p style="margin:10px auto;color:rgb(51,51,51);font-family:Verdana, Arial, Helvetica, sans-serif;background-color:rgb(255,255,255);"><span style="font-size:16px;">某个文件多处被用到可以存为一个变量</span></p> <div class="cnblogs_Highlighter sh-gutter" style="margin:0px;padding:0px;color:rgb(51,51,51);font-family:Verdana, Arial, Helvetica, sans-serif;font-size:14px;background-color:rgb(255,255,255);"> <div style="margin:0px;padding:0px;"> <div class="syntaxhighlighter python" style="padding:0px;width:806px;margin:1em 0px;font-size:1em;"> <table border="0" style="border-spacing:0px;max-width:850px;border:1px solid #C0C0C0;width:806px;margin:0px;padding:0px;background:none;float:none;height:auto;line-height:1.1em;vertical-align:baseline;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;font-size:12px;min-height:auto;"> <tbody style="margin:0px;padding:0px;background:none;float:none;height:auto;line-height:1.1em;vertical-align:baseline;width:auto;min-height:auto;"> <tr style="margin:0px;padding:0px;background:none;border-top:0px;float:none;height:auto;line-height:1.1em;vertical-align:baseline;width:auto;min-height:auto;"> <td class="gutter" style="padding:3px;border-color:#C0C0C0;border-collapse:collapse;margin:0px;background:none;float:none;height:auto;line-height:1.1em;vertical-align:baseline;width:35px;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;font-size:12px;min-height:auto;color:rgb(175,175,175);"> <div class="line number1 index0 alt2" style="margin:0px;padding:0px .5em;background:rgb(244,244,244) none;border-width:0px 2px 0px 0px;border-right-style:solid;border-right-color:rgb(108,226,108);float:none;height:auto;line-height:1.8em;text-align:right;vertical-align:baseline;width:auto;min-height:auto;white-space:nowrap;"> 1 </div> <div class="line number2 index1 alt1" style="margin:0px;padding:0px .5em;background-image:none;border-width:0px 2px 0px 0px;border-right-style:solid;border-right-color:rgb(108,226,108);float:none;height:auto;line-height:1.8em;text-align:right;vertical-align:baseline;width:auto;min-height:auto;white-space:nowrap;"> 2 </div> <div class="line number3 index2 alt2" style="margin:0px;padding:0px .5em;background:rgb(244,244,244) none;border-width:0px 2px 0px 0px;border-right-style:solid;border-right-color:rgb(108,226,108);float:none;height:auto;line-height:1.8em;text-align:right;vertical-align:baseline;width:auto;min-height:auto;white-space:nowrap;"> 3 </div></td> <td class="code" style="padding:3px;border-color:#C0C0C0;border-collapse:collapse;margin:0px;background:none;float:none;height:auto;line-height:1.1em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;font-size:12px;min-height:auto;"> <div class="container" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.1em;vertical-align:baseline;width:auto;min-height:auto;"> <div class="line number1 index0 alt2" style="margin:0px;padding:0px 1em;background:rgb(244,244,244) none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;min-height:auto;white-space:nowrap;"> <code class="python plain" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,0);">{</code> <code class="python keyword" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,255);">%</code>  <code class="python plain" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,0);">load static </code> <code class="python keyword" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,255);">%</code> <code class="python plain" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,0);">}</code> </div> <div class="line number2 index1 alt1" style="margin:0px;padding:0px 1em;background-image:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;min-height:auto;white-space:nowrap;"> <code class="python plain" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,0);">{</code> <code class="python keyword" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,255);">%</code>  <code class="python plain" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,0);">static </code> <code class="python string" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:#0000FF;">"images/hi.jpg"</code>  <code class="python plain" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,0);">as myphoto </code> <code class="python keyword" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,255);">%</code> <code class="python plain" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,0);">}</code> </div> <div class="line number3 index2 alt2" style="margin:0px;padding:0px 1em;background:rgb(244,244,244) none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;min-height:auto;white-space:nowrap;"> <code class="python plain" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,0);"><img src</code> <code class="python keyword" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,255);">=</code> <code class="python string" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:#0000FF;">"{{ myphoto }}"</code> <code class="python plain" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,0);">><</code> <code class="python keyword" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,255);">/</code> <code class="python plain" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,0);">img></code> </div> </div></td> </tr> </tbody> </table> </div> </div> </div> <p style="margin:10px auto;color:rgb(51,51,51);font-family:Verdana, Arial, Helvetica, sans-serif;background-color:rgb(255,255,255);"><span style="font-size:16px;">使用get_static_prefix</span></p> <div class="cnblogs_Highlighter sh-gutter" style="margin:0px;padding:0px;color:rgb(51,51,51);font-family:Verdana, Arial, Helvetica, sans-serif;font-size:14px;background-color:rgb(255,255,255);"> <div style="margin:0px;padding:0px;"> <div class="syntaxhighlighter python" style="padding:0px;width:806px;margin:1em 0px;font-size:1em;"> <table border="0" style="border-spacing:0px;max-width:850px;border:1px solid #C0C0C0;width:806px;margin:0px;padding:0px;background:none;float:none;height:auto;line-height:1.1em;vertical-align:baseline;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;font-size:12px;min-height:auto;"> <tbody style="margin:0px;padding:0px;background:none;float:none;height:auto;line-height:1.1em;vertical-align:baseline;width:auto;min-height:auto;"> <tr style="margin:0px;padding:0px;background:none;border-top:0px;float:none;height:auto;line-height:1.1em;vertical-align:baseline;width:auto;min-height:auto;"> <td class="gutter" style="padding:3px;border-color:#C0C0C0;border-collapse:collapse;margin:0px;background:none;float:none;height:auto;line-height:1.1em;vertical-align:baseline;width:35px;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;font-size:12px;min-height:auto;color:rgb(175,175,175);"> <div class="line number1 index0 alt2" style="margin:0px;padding:0px .5em;background:rgb(244,244,244) none;border-width:0px 2px 0px 0px;border-right-style:solid;border-right-color:rgb(108,226,108);float:none;height:auto;line-height:1.8em;text-align:right;vertical-align:baseline;width:auto;min-height:auto;white-space:nowrap;"> 1 </div> <div class="line number2 index1 alt1" style="margin:0px;padding:0px .5em;background-image:none;border-width:0px 2px 0px 0px;border-right-style:solid;border-right-color:rgb(108,226,108);float:none;height:auto;line-height:1.8em;text-align:right;vertical-align:baseline;width:auto;min-height:auto;white-space:nowrap;"> 2 </div></td> <td class="code" style="padding:3px;border-color:#C0C0C0;border-collapse:collapse;margin:0px;background:none;float:none;height:auto;line-height:1.1em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;font-size:12px;min-height:auto;"> <div class="container" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.1em;vertical-align:baseline;width:auto;min-height:auto;"> <div class="line number1 index0 alt2" style="margin:0px;padding:0px 1em;background:rgb(244,244,244) none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;min-height:auto;white-space:nowrap;"> <code class="python plain" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,0);">{</code> <code class="python keyword" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,255);">%</code>  <code class="python plain" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,0);">load static </code> <code class="python keyword" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,255);">%</code> <code class="python plain" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,0);">}</code> </div> <div class="line number2 index1 alt1" style="margin:0px;padding:0px 1em;background-image:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;min-height:auto;white-space:nowrap;"> <code class="python plain" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,0);"><img src</code> <code class="python keyword" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,255);">=</code> <code class="python string" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:#0000FF;">"{% get_static_prefix %}images/hi.jpg"</code>  <code class="python plain" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,0);">alt</code> <code class="python keyword" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,255);">=</code> <code class="python string" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:#0000FF;">"Hi!"</code>  <code class="python keyword" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,255);">/</code> <code class="python plain" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,0);">></code> </div> </div></td> </tr> </tbody> </table> </div> </div> </div> <p style="margin:10px auto;color:rgb(51,51,51);font-family:Verdana, Arial, Helvetica, sans-serif;background-color:rgb(255,255,255);"><span style="font-size:16px;">或者</span></p> <div class="cnblogs_Highlighter sh-gutter" style="margin:0px;padding:0px;color:rgb(51,51,51);font-family:Verdana, Arial, Helvetica, sans-serif;background-color:rgb(255,255,255);"> <div style="margin:0px;padding:0px;"> <div class="syntaxhighlighter python" style="font-size:1em;padding:0px;width:806px;margin:1em 0px;"> <table border="0" style="border-spacing:0px;max-width:850px;border:1px solid #C0C0C0;width:806px;margin:0px;padding:0px;background:none;float:none;height:auto;line-height:1.1em;vertical-align:baseline;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;font-size:12px;min-height:auto;"> <tbody style="margin:0px;padding:0px;background:none;float:none;height:auto;line-height:1.1em;vertical-align:baseline;width:auto;min-height:auto;"> <tr style="margin:0px;padding:0px;background:none;border-top:0px;float:none;height:auto;line-height:1.1em;vertical-align:baseline;width:auto;min-height:auto;"> <td class="gutter" style="padding:3px;border-color:#C0C0C0;border-collapse:collapse;margin:0px;background:none;float:none;height:auto;line-height:1.1em;vertical-align:baseline;width:35px;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;font-size:12px;min-height:auto;color:rgb(175,175,175);"> <div class="line number1 index0 alt2" style="margin:0px;padding:0px .5em;background:rgb(244,244,244) none;border-width:0px 2px 0px 0px;border-right-style:solid;border-right-color:rgb(108,226,108);float:none;height:auto;line-height:1.8em;text-align:right;vertical-align:baseline;width:auto;min-height:auto;white-space:nowrap;"> 1 </div> <div class="line number2 index1 alt1" style="margin:0px;padding:0px .5em;background-image:none;border-width:0px 2px 0px 0px;border-right-style:solid;border-right-color:rgb(108,226,108);float:none;height:auto;line-height:1.8em;text-align:right;vertical-align:baseline;width:auto;min-height:auto;white-space:nowrap;"> 2 </div> <div class="line number3 index2 alt2" style="margin:0px;padding:0px .5em;background:rgb(244,244,244) none;border-width:0px 2px 0px 0px;border-right-style:solid;border-right-color:rgb(108,226,108);float:none;height:auto;line-height:1.8em;text-align:right;vertical-align:baseline;width:auto;min-height:auto;white-space:nowrap;"> 3 </div> <div class="line number4 index3 alt1" style="margin:0px;padding:0px .5em;background-image:none;border-width:0px 2px 0px 0px;border-right-style:solid;border-right-color:rgb(108,226,108);float:none;height:auto;line-height:1.8em;text-align:right;vertical-align:baseline;width:auto;min-height:auto;white-space:nowrap;"> 4 </div> <div class="line number5 index4 alt2" style="margin:0px;padding:0px .5em;background:rgb(244,244,244) none;border-width:0px 2px 0px 0px;border-right-style:solid;border-right-color:rgb(108,226,108);float:none;height:auto;line-height:1.8em;text-align:right;vertical-align:baseline;width:auto;min-height:auto;white-space:nowrap;"> 5 </div></td> <td class="code" style="padding:3px;border-color:#C0C0C0;border-collapse:collapse;margin:0px;background:none;float:none;height:auto;line-height:1.1em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;font-size:12px;min-height:auto;"> <div class="container" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.1em;vertical-align:baseline;width:auto;min-height:auto;"> <div class="line number1 index0 alt2" style="margin:0px;padding:0px 1em;background:rgb(244,244,244) none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;min-height:auto;white-space:nowrap;"> <code class="python plain" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,0);">{</code> <code class="python keyword" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,255);">%</code>  <code class="python plain" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,0);">load static </code> <code class="python keyword" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,255);">%</code> <code class="python plain" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,0);">}</code> </div> <div class="line number2 index1 alt1" style="margin:0px;padding:0px 1em;background-image:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;min-height:auto;white-space:nowrap;"> <code class="python plain" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,0);">{</code> <code class="python keyword" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,255);">%</code>  <code class="python plain" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,0);">get_static_prefix as STATIC_PREFIX </code> <code class="python keyword" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,255);">%</code> <code class="python plain" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,0);">}</code> </div> <div class="line number3 index2 alt2" style="margin:0px;padding:0px 1em;background:rgb(244,244,244) none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;min-height:auto;white-space:nowrap;">   </div> <div class="line number4 index3 alt1" style="margin:0px;padding:0px 1em;background-image:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;min-height:auto;white-space:nowrap;"> <code class="python plain" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,0);"><img src</code> <code class="python keyword" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,255);">=</code> <code class="python string" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:#0000FF;">"{{ STATIC_PREFIX }}images/hi.jpg"</code>  <code class="python plain" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,0);">alt</code> <code class="python keyword" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,255);">=</code> <code class="python string" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:#0000FF;">"Hi!"</code>  <code class="python keyword" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,255);">/</code> <code class="python plain" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,0);">></code> </div> <div class="line number5 index4 alt2" style="margin:0px;padding:0px 1em;background:rgb(244,244,244) none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;min-height:auto;white-space:nowrap;"> <code class="python plain" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,0);"><img src</code> <code class="python keyword" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,255);">=</code> <code class="python string" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:#0000FF;">"{{ STATIC_PREFIX }}images/hi2.jpg"</code>  <code class="python plain" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,0);">alt</code> <code class="python keyword" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,255);">=</code> <code class="python string" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:#0000FF;">"Hello!"</code>  <code class="python keyword" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,255);">/</code> <code class="python plain" style="margin:0px;padding:0px;background:none;border:0px;float:none;height:auto;line-height:1.8em;vertical-align:baseline;width:auto;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;min-height:auto;white-space:nowrap;color:rgb(0,0,0);">></code> </div> </div></td> </tr> </tbody> </table> <br> </div> </div> </div> <div class="cnblogs_Highlighter sh-gutter" style="margin:0px;padding:0px;color:rgb(51,51,51);font-family:Verdana, Arial, Helvetica, sans-serif;font-size:14px;background-color:rgb(255,255,255);"> <div style="margin:0px;padding:0px;"></div> </div> <h3 style="margin-top:10px;margin-bottom:10px;padding:0px;line-height:1.5;color:rgb(51,51,51);font-family:Verdana, Arial, Helvetica, sans-serif;background-color:rgb(255,255,255);"><span style="font-size:18px;"><span style="font-family:'-apple-system', 'SF UI Text', Arial, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'WenQuanYi Micro Hei', sans-serif, SimHei, SimSun;background-color:rgb(255,255,255);">include 模板标签</span><span style="font-family:'-apple-system', 'SF UI Text', Arial, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'WenQuanYi Micro Hei', sans-serif, SimHei, SimSun;background-color:rgb(255,255,255);"> </span></span></h3> <p></p> <p style="font-family:'-apple-system', 'SF UI Text', Arial, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'WenQuanYi Micro Hei', sans-serif, SimHei, SimSun;background-color:rgb(255,255,255);">内建模板标签:该标签允许在(模板中)包含其它的模板的内容。就是html里面的iframe <br>下面这两个例子都包含了 nav.html 模板。这两个例子是等价的,它们证明单/双引号都是允许的。</p> <pre class="prettyprint" style="font-size:14px;line-height:22px;"><code class="hljs ruby has-numbering">{% <span class="hljs-keyword" style="margin:0px;padding:0px;">include</span> <span class="hljs-string" style="margin:0px;padding:0px;">'nav.html'</span> %} {% <span class="hljs-keyword" style="margin:0px;padding:0px;">include</span> <span class="hljs-string" style="margin:0px;padding:0px;">"nav.html"</span> %}</code></pre> <ul class="pre-numbering"> <li style="color:rgb(153,153,153);">1</li> <li style="color:rgb(153,153,153);">2</li> </ul> <p style="font-family:'-apple-system', 'SF UI Text', Arial, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'WenQuanYi Micro Hei', sans-serif, SimHei, SimSun;background-color:rgb(255,255,255);">下面的例子包含了 includes/nav.html 模板的内容:</p> <pre class="prettyprint" style="font-size:14px;line-height:22px;"><code class="hljs ruby has-numbering">{% <span class="hljs-keyword" style="margin:0px;padding:0px;">include</span> <span class="hljs-string" style="margin:0px;padding:0px;">'includes/nav.html'</span> %}</code></pre> <ul class="pre-numbering"> <li style="color:rgb(153,153,153);">1</li> </ul> <p style="font-family:'-apple-system', 'SF UI Text', Arial, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'WenQuanYi Micro Hei', sans-serif, SimHei, SimSun;background-color:rgb(255,255,255);">下面的例子包含了以变量 template_name 的值为名称的模板内容:</p> <pre class="prettyprint" style="font-size:14px;line-height:22px;"><code class="hljs django has-numbering"><span class="xml" style="margin:0px;padding:0px;"></span><span class="hljs-template_tag" style="margin:0px;padding:0px;">{% <span class="hljs-keyword" style="margin:0px;padding:0px;">include</span> template_name %}</span><span style="color:rgb(79,79,79);font-size:16px;text-align:justify;background-color:rgb(255,255,255);font-family:'-apple-system', 'SF UI Text', Arial, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'WenQuanYi Micro Hei', sans-serif, SimHei, SimSun;"><span style="font-size:24px;"> </span></span></code></pre> <p style="font-family:'-apple-system', 'SF UI Text', Arial, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'WenQuanYi Micro Hei', sans-serif, SimHei, SimSun;background-color:rgb(255,255,255);"></p> <p><strong><span style="font-size:18px;"><br></span></strong></p> <p><strong><span style="font-size:24px;">模板继承</span></strong></p> <p><strong><span style="font-size:24px;"><br></span></strong></p>本质上来说,模板继承就是先构造一个基础框架模板,而后在其子模板中对它所包含站点公用部分和定义块进行重载。  <br>就是说,比如每个网页都包含 <code style="font-size:14px;line-height:22px;padding:4px 2px 0px;"><HTML></HTML></code> 等重复的代码  <br> <strong>第一步是定义 基础模板</strong> , 该框架之后将由 子模板 所继承。 以下是我们目前所讲述范例的基础模板 <pre class="prettyprint" style="font-size:14px;line-height:22px;"><code class="hljs django has-numbering"><span class="xml" style="margin:0px;padding:0px;"><span class="hljs-doctype" style="margin:0px;padding:0px;"><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"></span> <span class="hljs-tag" style="margin:0px;padding:0px;"><<span class="hljs-title" style="margin:0px;padding:0px;">html</span> <span class="hljs-attribute" style="margin:0px;padding:0px;">lang</span>=<span class="hljs-value" style="margin:0px;padding:0px;">"en"</span>></span> <span class="hljs-tag" style="margin:0px;padding:0px;"><<span class="hljs-title" style="margin:0px;padding:0px;">head</span>></span> <span class="hljs-tag" style="margin:0px;padding:0px;"><<span class="hljs-title" style="margin:0px;padding:0px;">title</span>></span></span><span class="hljs-template_tag" style="margin:0px;padding:0px;">{% <span class="hljs-keyword" style="margin:0px;padding:0px;">block</span> title %}</span><span class="xml" style="margin:0px;padding:0px;"></span><span class="hljs-template_tag" style="margin:0px;padding:0px;">{% <span class="hljs-keyword" style="margin:0px;padding:0px;">endblock</span> %}</span><span class="xml" style="margin:0px;padding:0px;"><span class="hljs-tag" style="margin:0px;padding:0px;"></<span class="hljs-title" style="margin:0px;padding:0px;">title</span>></span> <span class="hljs-tag" style="margin:0px;padding:0px;"></<span class="hljs-title" style="margin:0px;padding:0px;">head</span>></span> <span class="hljs-tag" style="margin:0px;padding:0px;"><<span class="hljs-title" style="margin:0px;padding:0px;">body</span>></span> <span class="hljs-tag" style="margin:0px;padding:0px;"><<span class="hljs-title" style="margin:0px;padding:0px;">h1</span>></span>My helpful timestamp site<span class="hljs-tag" style="margin:0px;padding:0px;"></<span class="hljs-title" style="margin:0px;padding:0px;">h1</span>></span> </span><span class="hljs-template_tag" style="margin:0px;padding:0px;">{% <span class="hljs-keyword" style="margin:0px;padding:0px;">block</span> content %}</span><span class="xml" style="margin:0px;padding:0px;"></span><span class="hljs-template_tag" style="margin:0px;padding:0px;">{% <span class="hljs-keyword" style="margin:0px;padding:0px;">endblock</span> %}</span><span class="xml" style="margin:0px;padding:0px;"> </span><span class="hljs-template_tag" style="margin:0px;padding:0px;">{% <span class="hljs-keyword" style="margin:0px;padding:0px;">block</span> footer %}</span><span class="xml" style="margin:0px;padding:0px;"> <span class="hljs-tag" style="margin:0px;padding:0px;"><<span class="hljs-title" style="margin:0px;padding:0px;">hr</span>></span> <span class="hljs-tag" style="margin:0px;padding:0px;"><<span class="hljs-title" style="margin:0px;padding:0px;">p</span>></span>Thanks for visiting my site.<span class="hljs-tag" style="margin:0px;padding:0px;"></<span class="hljs-title" style="margin:0px;padding:0px;">p</span>></span> </span><span class="hljs-template_tag" style="margin:0px;padding:0px;">{% <span class="hljs-keyword" style="margin:0px;padding:0px;">endblock</span> %}</span><span class="xml" style="margin:0px;padding:0px;"> <span class="hljs-tag" style="margin:0px;padding:0px;"></<span class="hljs-title" style="margin:0px;padding:0px;">body</span>></span> <span class="hljs-tag" style="margin:0px;padding:0px;"></<span class="hljs-title" style="margin:0px;padding:0px;">html</span>></span></span></code></pre> <p>这个叫做 base.html 的模板定义了一个简单的 HTML 框架文档,我们将在本站点的所有页面中使用。<strong> </strong></p> <p><strong>子模板的作用就是重载、添加或保留那些块的内容。</strong> </p>我们使用一个以前已经见过的模板标签: {% block %} 。 所有的 {% block %} 标签告诉模板引擎,子模板可以重载这些部分。 每个{% block %}标签所要做的是告诉模板引擎,该模板下的这一块内容将有可能被子模板覆盖。  <br>现在我们已经有了一个基本模板,我们可以修改 current_datetime.html 模板来 使用它。 <pre class="prettyprint" style="font-size:14px;line-height:22px;"><code class="hljs django has-numbering"><span class="xml" style="margin:0px;padding:0px;"></span><span class="hljs-template_tag" style="margin:0px;padding:0px;">{% <span class="hljs-keyword" style="margin:0px;padding:0px;">extends</span> "base.html" %}</span><span class="xml" style="margin:0px;padding:0px;"> </span><span class="hljs-template_tag" style="margin:0px;padding:0px;">{% <span class="hljs-keyword" style="margin:0px;padding:0px;">block</span> title %}</span><span class="xml" style="margin:0px;padding:0px;">The current time</span><span class="hljs-template_tag" style="margin:0px;padding:0px;">{% <span class="hljs-keyword" style="margin:0px;padding:0px;">endblock</span> %}</span><span class="xml" style="margin:0px;padding:0px;"> </span><span class="hljs-template_tag" style="margin:0px;padding:0px;">{% <span class="hljs-keyword" style="margin:0px;padding:0px;">block</span> content %}</span><span class="xml" style="margin:0px;padding:0px;"> <span class="hljs-tag" style="margin:0px;padding:0px;"><<span class="hljs-title" style="margin:0px;padding:0px;">p</span>></span>It is now </span><span class="hljs-variable" style="margin:0px;padding:0px;">{{ current_date }}</span><span class="xml" style="margin:0px;padding:0px;">.<span class="hljs-tag" style="margin:0px;padding:0px;"></<span class="hljs-title" style="margin:0px;padding:0px;">p</span>></span> </span><span class="hljs-template_tag" style="margin:0px;padding:0px;">{% <span class="hljs-keyword" style="margin:0px;padding:0px;">endblock</span> %}</span></code></pre> <p style="font-family:'-apple-system', 'SF UI Text', Arial, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'WenQuanYi Micro Hei', sans-serif, SimHei, SimSun;background-color:rgb(255,255,255);"><strong>模板引擎发现了 {% extends %} 标签, 注意到该模板是一个子模板。 模板引擎立即装载其父模板,即本例中的 base.html 。 </strong><br>模板引擎注意到 base.html 中的三个 {% block %} 标签,并用子模板的内容替换这些 block 。因此,引擎将会使用我们在 { block title %} 中定义的标题,对 {% block content %} 也是如此。 所以,网页标题一块将由 {% block title %}替换,同样地,网页的内容一块将由 {% block content %}替换。 <br></p> <p><strong>注意由于子模板并没有定义 footer 块,模板系统将使用在父模板中定义的值。</strong> 父模板 {% block %} 标签中的内容总是被当作一条退路。</p> <p><br></p> <p><br></p> <h2 style="color:rgb(51,51,51);margin-top:20px;margin-bottom:20px;line-height:1.5;padding:0px;font-family:Verdana, Arial, Helvetica, sans-serif;background-color:rgb(255,255,255);"></h2> <p style="font-family:'-apple-system', 'SF UI Text', Arial, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'WenQuanYi Micro Hei', sans-serif, SimHei, SimSun;background-color:rgb(255,255,255);"><strong><span style="font-size:24px;">使用继承的一种常见方式是下面的三层法:</span></strong></p> <p style="font-family:'-apple-system', 'SF UI Text', Arial, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'WenQuanYi Micro Hei', sans-serif, SimHei, SimSun;background-color:rgb(255,255,255);">创建 base.html 模板,在其中定义站点的主要外观感受。 这些都是不常修改甚至从不修改的部分。</p> <p style="font-family:'-apple-system', 'SF UI Text', Arial, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'WenQuanYi Micro Hei', sans-serif, SimHei, SimSun;background-color:rgb(255,255,255);">为网站的每个区域创建 base_SECTION.html 模板(例如, base_photos.html 和 base_forum.html )。这些模板对 base.html 进行拓展,并包含区域特定的风格与设计。</p> <p style="font-family:'-apple-system', 'SF UI Text', Arial, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'WenQuanYi Micro Hei', sans-serif, SimHei, SimSun;background-color:rgb(255,255,255);">为每种类型的页面创建独立的模板,例如论坛页面或者图片库。 这些模板拓展相应的区域模板。</p> <p style="font-family:'-apple-system', 'SF UI Text', Arial, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'WenQuanYi Micro Hei', sans-serif, SimHei, SimSun;background-color:rgb(255,255,255);">这个方法可最大限度地重用代码,并使得向公共区域(如区域级的导航)添加内容成为一件轻松的工作。</p> <p style="font-family:'-apple-system', 'SF UI Text', Arial, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'WenQuanYi Micro Hei', sans-serif, SimHei, SimSun;background-color:rgb(255,255,255);"><br></p> <p style="font-family:'-apple-system', 'SF UI Text', Arial, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'WenQuanYi Micro Hei', sans-serif, SimHei, SimSun;background-color:rgb(255,255,255);"><br></p> <p style="font-family:'-apple-system', 'SF UI Text', Arial, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'WenQuanYi Micro Hei', sans-serif, SimHei, SimSun;background-color:rgb(255,255,255);"><strong><span style="font-size:24px;">以下是使用模板继承的一些诀窍:</span></strong></p> <p style="font-family:'-apple-system', 'SF UI Text', Arial, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'WenQuanYi Micro Hei', sans-serif, SimHei, SimSun;background-color:rgb(255,255,255);">如果在模板中使用 {% extends %} ,必须保证其为模板中的第一个模板标记。 否则,模板继承将不起作用。</p> <p style="font-family:'-apple-system', 'SF UI Text', Arial, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'WenQuanYi Micro Hei', sans-serif, SimHei, SimSun;background-color:rgb(255,255,255);">一般来说,基础模板中的 {% block %} 标签越多越好。 记住,子模板不必定义父模板中所有的代码块,因此你可以用合理的缺省值对一些代码块进行填充,然后只对子模板所需的代码块进行(重)定义。 俗话说,钩子越多越好。</p> <p style="font-family:'-apple-system', 'SF UI Text', Arial, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'WenQuanYi Micro Hei', sans-serif, SimHei, SimSun;background-color:rgb(255,255,255);">如果发觉自己在多个模板之间拷贝代码,你应该考虑将该代码段放置到父模板的某个 {% block %} 中。</p> <p style="font-family:'-apple-system', 'SF UI Text', Arial, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'WenQuanYi Micro Hei', sans-serif, SimHei, SimSun;background-color:rgb(255,255,255);">如果你需要访问父模板中的块的内容,使用 <strong>{{ block.super }}</strong>这个标签吧,这一个魔法变量将会表现出父模板中的内容。 如果只想在上级代码块基础上添加内容,而不是全部重载,该变量就显得非常有用了。</p> <p style="font-family:'-apple-system', 'SF UI Text', Arial, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'WenQuanYi Micro Hei', sans-serif, SimHei, SimSun;background-color:rgb(255,255,255);">不允许在同一个模板中定义多个同名的 {% block %} 。 存在这样的限制是因为<strong>block 标签的工作方式是双向的</strong>。 <strong>也就是说,block 标签不仅挖了一个要填的坑,也定义了在父模板中这个坑所填充的内容。</strong>如果模板中出现了两个相同名称的 {% block %} 标签,父模板将无从得知要使用哪个块的内容。</p> <p style="font-family:'-apple-system', 'SF UI Text', Arial, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'WenQuanYi Micro Hei', sans-serif, SimHei, SimSun;background-color:rgb(255,255,255);">{% extends %} 对所传入模板名称使用的加载方法和 get_template() 相同。 也就是说,会将模板名称被添加到 TEMPLATE_DIRS 设置之后。</p> <p style="font-family:'-apple-system', 'SF UI Text', Arial, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'WenQuanYi Micro Hei', sans-serif, SimHei, SimSun;background-color:rgb(255,255,255);">多数情况下, {% extends %} 的参数应该是字符串,但是如果直到运行时方能确定父模板名,这个参数也可以是个变量。 这使得你能够实现一些很酷的动态功能。</p> <p style="font-family:'-apple-system', 'SF UI Text', Arial, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'WenQuanYi Micro Hei', sans-serif, SimHei, SimSun;background-color:rgb(255,255,255);"><br></p> <p style="font-family:'-apple-system', 'SF UI Text', Arial, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'WenQuanYi Micro Hei', sans-serif, SimHei, SimSun;background-color:rgb(255,255,255);"><br></p> <p style="font-family:'-apple-system', 'SF UI Text', Arial, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'WenQuanYi Micro Hei', sans-serif, SimHei, SimSun;background-color:rgb(255,255,255);"></p> <p><span style="font-size:18px;"><span style="font-weight:700;">如何在视图中使用模板</span> </span></p>模版是以Html形式显示的。要在django中使用,首先要告诉模版存放在那里。也就是模版加载。打开你的settings.py配置文件,配置如下:  <br> <img src="http://img.e-com-net.com/image/info8/c905cfe2894d4edc8c252eab8464e6c6.jpg" alt="这里写图片描述" title="" style="border:0px;margin-top:24px;margin-bottom:24px;" width="0" height="0"> <br>你可以任意指定想要的目录,只要运行 Web 服务器的用户可以读取该目录的子目录和模板文件 <p style="font-family:'-apple-system', 'SF UI Text', Arial, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'WenQuanYi Micro Hei', sans-serif, SimHei, SimSun;background-color:rgb(255,255,255);">使用方式: <br>1.render <br>2.render_to_response <br>3.get_template() <br>个人比较支持第1和2的方式 <br><img src="http://img.e-com-net.com/image/info8/fa82e6a5e108468aa11f02783fe81783.jpg" alt="这里写图片描述" title="" style="border:0px;margin-top:24px;margin-bottom:24px;" width="0" height="0"></p> <br> </div> </div> </div> </div> </div> <!--PC和WAP自适应版--> <div id="SOHUCS" sid="1276084840105525248"></div> <script type="text/javascript" src="/views/front/js/chanyan.js"></script> <!-- 文章页-底部 动态广告位 --> <div class="youdao-fixed-ad" id="detail_ad_bottom"></div> </div> <div class="col-md-3"> <div class="row" id="ad"> <!-- 文章页-右侧1 动态广告位 --> <div id="right-1" class="col-lg-12 col-md-12 col-sm-4 col-xs-4 ad"> <div class="youdao-fixed-ad" id="detail_ad_1"> </div> </div> <!-- 文章页-右侧2 动态广告位 --> <div id="right-2" class="col-lg-12 col-md-12 col-sm-4 col-xs-4 ad"> <div class="youdao-fixed-ad" id="detail_ad_2"></div> </div> <!-- 文章页-右侧3 动态广告位 --> <div id="right-3" class="col-lg-12 col-md-12 col-sm-4 col-xs-4 ad"> <div class="youdao-fixed-ad" id="detail_ad_3"></div> </div> </div> </div> </div> </div> </div> <div class="container"> <h4 class="pt20 mb15 mt0 border-top">你可能感兴趣的:(Django)</h4> <div id="paradigm-article-related"> <div class="recommend-post mb30"> <ul class="widget-links"> <li><a href="/article/1891369448250601472.htm" title="asp.net javascrip获取session的值_一篇文章搞定 Django Cookie 与 Session" target="_blank">asp.net javascrip获取session的值_一篇文章搞定 Django Cookie 与 Session</a> <span class="text-muted">weixin_39962285</span> <a class="tag" taget="_blank" href="/search/asp.net/1.htm">asp.net</a><a class="tag" taget="_blank" href="/search/html%E8%8E%B7%E5%8F%96session%E7%9A%84%E5%80%BC/1.htm">html获取session的值</a><a class="tag" taget="_blank" href="/search/session%E4%BF%9D%E5%AD%98%E5%AF%86%E7%A0%81/1.htm">session保存密码</a><a class="tag" taget="_blank" href="/search/session%E5%A4%B1%E6%95%88/1.htm">session失效</a><a class="tag" taget="_blank" href="/search/%E5%89%8D%E7%AB%AF%E6%80%8E%E4%B9%88%E8%8E%B7%E5%8F%96session%E7%9A%84%E5%80%BC/1.htm">前端怎么获取session的值</a> <div>cookieCookie的由来大家都知道HTTP协议是无状态的。无状态的意思是每次请求都是独立的,它的执行情况和结果与前面的请求和之后的请求都无直接关系,它不会受前面的请求响应情况直接影响,也不会直接影响后面的请求响应情况。一句有意思的话来描述就是人生只如初见,对服务器来说,每次的请求都是全新的。状态可以理解为客户端和服务器在某次会话中产生的数据,那无状态的就以为这些数据不会被保留。会话中产生的数</div> </li> <li><a href="/article/1891259214886662144.htm" title="大数据知识图谱之深度学习——基于BERT+LSTM+CRF深度学习识别模型医疗知识图谱问答可视化系统_bert+lstm" target="_blank">大数据知识图谱之深度学习——基于BERT+LSTM+CRF深度学习识别模型医疗知识图谱问答可视化系统_bert+lstm</a> <span class="text-muted">2301_76348014</span> <a class="tag" taget="_blank" href="/search/%E7%A8%8B%E5%BA%8F%E5%91%98/1.htm">程序员</a><a class="tag" taget="_blank" href="/search/%E6%B7%B1%E5%BA%A6%E5%AD%A6%E4%B9%A0/1.htm">深度学习</a><a class="tag" taget="_blank" href="/search/%E5%A4%A7%E6%95%B0%E6%8D%AE/1.htm">大数据</a><a class="tag" taget="_blank" href="/search/%E7%9F%A5%E8%AF%86%E5%9B%BE%E8%B0%B1/1.htm">知识图谱</a> <div>文章目录大数据知识图谱之深度学习——基于BERT+LSTM+CRF深度学习识别模型医疗知识图谱问答可视化系统一、项目概述二、系统实现基本流程三、项目工具所用的版本号四、所需要软件的安装和使用五、开发技术简介Django技术介绍Neo4j数据库Bootstrap4框架Echarts简介NavicatPremium15简介Layui简介Python语言介绍MySQL数据库深度学习六、核心理论贪心算法A</div> </li> <li><a href="/article/1891215839458291712.htm" title="8.12 orm-聚合查询" target="_blank">8.12 orm-聚合查询</a> <span class="text-muted">yangshiting84</span> <a class="tag" taget="_blank" href="/search/%E6%9A%91%E6%9C%9F%E8%A7%84%E5%88%92/1.htm">暑期规划</a><a class="tag" taget="_blank" href="/search/django/1.htm">django</a><a class="tag" taget="_blank" href="/search/python/1.htm">python</a><a class="tag" taget="_blank" href="/search/%E5%90%8E%E7%AB%AF/1.htm">后端</a> <div>8.12orm-聚合查询聚合查询(aggregate)聚合查询函数是对一组值执行计算,并返回单个值。Django使用聚合查询前要先从django.db.models引入Avg、Max、Min、Count、Sum(首字母大写)。fromdjango.db.modelsimportAvg,Max,Min,Count,Sum#引入函数聚合查询返回值的数据类型是字典。聚合函数aggregate()是Que</div> </li> <li><a href="/article/1891215208785965056.htm" title="Django-ORM 单表查询" target="_blank">Django-ORM 单表查询</a> <span class="text-muted">本木夕丶Lu</span> <a class="tag" taget="_blank" href="/search/django/1.htm">django</a><a class="tag" taget="_blank" href="/search/python/1.htm">python</a><a class="tag" taget="_blank" href="/search/%E5%90%8E%E7%AB%AF/1.htm">后端</a> <div>文章目录数据准备一、查询关键字1.1QuerySet对象first方法last方法values方法values_list方法count()exists()1.2all()1.3filter(**kwargs)1.4get(**kwargs)--不推荐使用1.5exclude(**kwargs)1.6order_by(\*field)1.7reverse()1.8distinct()二、基于双下划线</div> </li> <li><a href="/article/1891210164418179072.htm" title="06 Django-orm-多表操作" target="_blank">06 Django-orm-多表操作</a> <span class="text-muted">lzplum619</span> <a class="tag" taget="_blank" href="/search/Django/1.htm">Django</a><a class="tag" taget="_blank" href="/search/Linux%E7%9B%B8%E5%85%B3/1.htm">Linux相关</a><a class="tag" taget="_blank" href="/search/django/1.htm">django</a><a class="tag" taget="_blank" href="/search/python/1.htm">python</a> <div>一创建模型实例:我们来假定下面这些概念,字段和关系作者模型:一个作者有姓名和年龄。作者详细模型:把作者的详情放到详情表,包含生日,手机号,家庭住址等信息。作者详情模型和作者模型之间是一对一的关系(one-to-one)出版商模型:出版商有名称,所在城市以及email。书籍模型:书籍有书名和出版日期,一本书可能会有多个作者,一个作者也可以写多本书,所以作者和书籍的关系就是多对多的关联关系(many-</div> </li> <li><a href="/article/1891205120897642496.htm" title="Django ORM - 聚合查询" target="_blank">Django ORM - 聚合查询</a> <span class="text-muted">lsx202406</span> <a class="tag" taget="_blank" href="/search/%E5%BC%80%E5%8F%91%E8%AF%AD%E8%A8%80/1.htm">开发语言</a> <div>DjangoORM-聚合查询引言Django是一个强大的PythonWeb框架,它拥有一个功能丰富的对象关系映射(Object-RelationalMapping,简称ORM)。ORM允许开发者以Python类和对象的交互方式来操作数据库,而不是直接编写SQL查询。本文将深入探讨DjangoORM中的聚合查询功能,包括其基本用法、常用函数以及在实际开发中的应用场景。聚合查询简介聚合查询,顾名思义,</div> </li> <li><a href="/article/1891033273690288128.htm" title="关于django __str__ 与 __unicode__ 问题" target="_blank">关于django __str__ 与 __unicode__ 问题</a> <span class="text-muted">weixin_40105587</span> <a class="tag" taget="_blank" href="/search/python/1.htm">python</a> <div>因为所有字符串都作为Unicode字符串从数据库返回,基于字符的模型字段(CharField、TextField、URLField等)在Django从数据库检索数据时将包含Unicode值。即使数据可以放入ASCII字节字符串,也总是如此。您可以在创建模型或填充字段时传入bytestring,并且Django会在需要时将其转换为Unicode。¶选择__str__()和__unicode__()请</div> </li> <li><a href="/article/1891030370376282112.htm" title="django上传文件" target="_blank">django上传文件</a> <span class="text-muted">大得369</span> <a class="tag" taget="_blank" href="/search/django/1.htm">django</a><a class="tag" taget="_blank" href="/search/sqlite/1.htm">sqlite</a><a class="tag" taget="_blank" href="/search/python/1.htm">python</a> <div>1、settings.py配置#静态文件配置STATIC_URL='/static/'STATICFILES_DIRS=[BASE_DIR/'static',]上传文件#定义一个视图函数,该函数接收一个request参数fromdjango.shortcutsimportrender#必备引入importjsonfromdjango.views.decorators.httpimportrequi</div> </li> <li><a href="/article/1891023435866370048.htm" title="青少年编程与数学 02-009 Django 5 Web 编程 14课题、命名空间" target="_blank">青少年编程与数学 02-009 Django 5 Web 编程 14课题、命名空间</a> <span class="text-muted">明月看潮生</span> <a class="tag" taget="_blank" href="/search/%E7%BC%96%E7%A8%8B%E4%B8%8E%E6%95%B0%E5%AD%A6/1.htm">编程与数学</a><a class="tag" taget="_blank" href="/search/%E7%AC%AC02%E9%98%B6%E6%AE%B5/1.htm">第02阶段</a><a class="tag" taget="_blank" href="/search/%E9%9D%92%E5%B0%91%E5%B9%B4%E7%BC%96%E7%A8%8B/1.htm">青少年编程</a><a class="tag" taget="_blank" href="/search/django/1.htm">django</a><a class="tag" taget="_blank" href="/search/%E7%BC%96%E7%A8%8B%E4%B8%8E%E6%95%B0%E5%AD%A6/1.htm">编程与数学</a><a class="tag" taget="_blank" href="/search/python/1.htm">python</a> <div>青少年编程与数学02-009Django5Web编程14课题、命名空间一、命名空间命名空间的作用如何定义和使用命名空间定义命名空间使用命名空间命名空间的注意事项二、命名空间的好处1.**避免URL名称冲突**2.**提高代码的可读性和可维护性**3.**增强应用的可重用性**4.**支持复杂的URL结构**5.**便于团队协作和文档编写**三、练习步骤1:创建项目和应用步骤2:定义模型`blog/</div> </li> <li><a href="/article/1891022173833850880.htm" title="python flask django在线投票系统 md14i" target="_blank">python flask django在线投票系统 md14i</a> <span class="text-muted">专注分享bishe530</span> <a class="tag" taget="_blank" href="/search/python/1.htm">python</a><a class="tag" taget="_blank" href="/search/flask/1.htm">flask</a><a class="tag" taget="_blank" href="/search/django/1.htm">django</a> <div>文章目录具体实现截图项目技术介绍论文写作思路核心代码部分展示可定制开发功能创新亮点django项目示例源码/演示视频获取方式具体实现截图项目技术介绍Python版本:python3.7以上框架支持:flask/django开发软件:PyCharm数据库:mysql数据库工具:Navicat浏览器:谷歌浏览器(PycharmFlaskDjangoVuemysql)论文写作思路第一部分绪论,主要介绍所</div> </li> <li><a href="/article/1890967070233915392.htm" title="ubuntu20.04中vscode配置django" target="_blank">ubuntu20.04中vscode配置django</a> <span class="text-muted">Galaxy_1229</span> <a class="tag" taget="_blank" href="/search/vscode/1.htm">vscode</a><a class="tag" taget="_blank" href="/search/django/1.htm">django</a><a class="tag" taget="_blank" href="/search/ide/1.htm">ide</a> <div>1.下载插件我用的是这两个2.配置环境Ubuntu20.04创建虚拟环境python3-mvenv.venv没有venv的记得装一下sudoaptinstallpython3.8-venv装好之后,会出现.venv的文件夹找一下activate,我的在bin里按照提示sourcebin/activate完成后会显示(.venv)的虚拟环境,然后我们安装一下djangopipinstalldjang</div> </li> <li><a href="/article/1890927088047812608.htm" title="vue和Django快速创建项目" target="_blank">vue和Django快速创建项目</a> <span class="text-muted">CCSBRIDGE</span> <a class="tag" taget="_blank" href="/search/%E4%BA%86%E8%A7%A3Vue/1.htm">了解Vue</a><a class="tag" taget="_blank" href="/search/vue.js/1.htm">vue.js</a><a class="tag" taget="_blank" href="/search/%E5%89%8D%E7%AB%AF/1.htm">前端</a><a class="tag" taget="_blank" href="/search/javascript/1.htm">javascript</a> <div>一、VUE1.创建Vue3+JavaScript项目npmcreatevite@latest项目名称----templatevue创建Vue3+TypeScript项目npmcreatevite@latest项目名称----templatevue-ts2.然后cd项目名称npminstallnpminstallaxios#发送API请求npminstallpinia#Vue3推荐的状态管理库npm</div> </li> <li><a href="/article/1890837945800257536.htm" title="500道Python毕业设计题目推荐,附源码" target="_blank">500道Python毕业设计题目推荐,附源码</a> <span class="text-muted">Java老徐</span> <a class="tag" taget="_blank" href="/search/Python/1.htm">Python</a><a class="tag" taget="_blank" href="/search/%E6%AF%95%E4%B8%9A%E8%AE%BE%E8%AE%A1/1.htm">毕业设计</a><a class="tag" taget="_blank" href="/search/python/1.htm">python</a><a class="tag" taget="_blank" href="/search/%E8%AF%BE%E7%A8%8B%E8%AE%BE%E8%AE%A1/1.htm">课程设计</a><a class="tag" taget="_blank" href="/search/notepad%2B%2B/1.htm">notepad++</a><a class="tag" taget="_blank" href="/search/Python%E6%AF%95%E4%B8%9A%E8%AE%BE%E8%AE%A1%E9%A2%98%E7%9B%AE/1.htm">Python毕业设计题目</a><a class="tag" taget="_blank" href="/search/%E6%AF%95%E4%B8%9A%E8%AE%BE%E8%AE%A1%E9%A2%98%E7%9B%AE%E6%8E%A8%E8%8D%90/1.htm">毕业设计题目推荐</a><a class="tag" taget="_blank" href="/search/%E6%AF%95%E4%B8%9A%E8%AE%BE%E8%AE%A1%E9%A2%98%E7%9B%AE/1.htm">毕业设计题目</a> <div>博主介绍:✌Java老徐、7年大厂程序员经历。全网粉丝12w+、csdn博客专家、掘金/华为云/阿里云/InfoQ等平台优质作者、专注于Java技术领域和毕业项目实战✌文末获取源码联系精彩专栏推荐订阅不然下次找不到哟Java基于微信小程序的校园外卖平台设计与实现,附源码Python基于Django的微博热搜、微博舆论可视化系统,附源码Java基于SpringBoot+Vue的学生宿舍管理系统感兴趣</div> </li> <li><a href="/article/1890811096684621824.htm" title="Django中间件的使用及功能" target="_blank">Django中间件的使用及功能</a> <span class="text-muted">.明天的自己</span> <a class="tag" taget="_blank" href="/search/python/1.htm">python</a><a class="tag" taget="_blank" href="/search/%E4%B8%AD%E9%97%B4%E4%BB%B6/1.htm">中间件</a> <div>Django中间件的使用及功能什么是中间件中间件应用于request与服务端之间和服务端与response之间,客户端发起请求到服务端接收可以通过中间件,服务端返回响应与客户端接收响应可以通过中间件,也就是说中间件可以处理request和response。中间件是Django请求/响应处理的钩子框架,也是一个非常重要的插件,用于改变Djang全局的输入以及输出.每个中间件都负责执行一些特定的功能.</div> </li> <li><a href="/article/1890807693233418240.htm" title="188、探索Django中间件:请求与响应的拦截与处理的艺术" target="_blank">188、探索Django中间件:请求与响应的拦截与处理的艺术</a> <span class="text-muted">多多的编程笔记</span> <a class="tag" taget="_blank" href="/search/django/1.htm">django</a><a class="tag" taget="_blank" href="/search/%E4%B8%AD%E9%97%B4%E4%BB%B6/1.htm">中间件</a><a class="tag" taget="_blank" href="/search/python/1.htm">python</a> <div>Python开发框架Django之中间件:处理请求与响应的拦截与处理引言想象一下,你正在一家餐厅享用美食。当你点的菜品端上桌时,你希望它既美味又符合你的口味。在软件开发中,尤其是在Web应用开发中,我们需要确保接收到的请求既有效又符合我们的业务规则。这就是Django中间件的作用——作为请求和响应的处理过程中的一个环节,它允许我们在请求到达视图之前对其进行修改,或在响应发送给客户端之前进行修改。本</div> </li> <li><a href="/article/1890791169252716544.htm" title="如何使用Django中间件" target="_blank">如何使用Django中间件</a> <span class="text-muted">AI航海家(Ethan)</span> <a class="tag" taget="_blank" href="/search/Django/1.htm">Django</a><a class="tag" taget="_blank" href="/search/python/1.htm">python</a><a class="tag" taget="_blank" href="/search/%E5%90%8E%E7%AB%AF%E6%A1%86%E6%9E%B6/1.htm">后端框架</a><a class="tag" taget="_blank" href="/search/django/1.htm">django</a><a class="tag" taget="_blank" href="/search/%E4%B8%AD%E9%97%B4%E4%BB%B6/1.htm">中间件</a><a class="tag" taget="_blank" href="/search/python/1.htm">python</a><a class="tag" taget="_blank" href="/search/%E5%90%8E%E7%AB%AF/1.htm">后端</a><a class="tag" taget="_blank" href="/search/postgresql/1.htm">postgresql</a> <div>如何使用Django中间件让访问更安全?嘿,朋友们!今天我们来聊聊如何在Django中使用自定义中间件保证某个文件夹的访问需要token验证。毕竟,有时候我们需要确保只有合法用户才能访问某些资源,对不对?什么是中间件?简单来说,中间件就是一种在Django应用请求和响应过程中拦截并处理请求的组件。它们在请求到达视图之前、在响应到达客户端之前能够进行各种操作。比如本次,我们将实现一个简单的token</div> </li> <li><a href="/article/1890758886219116544.htm" title="Python网络编程05----django与数据库的交互" target="_blank">Python网络编程05----django与数据库的交互</a> <span class="text-muted">翻滚吧挨踢男</span> <a class="tag" taget="_blank" href="/search/Python/1.htm">Python</a><a class="tag" taget="_blank" href="/search/python/1.htm">python</a><a class="tag" taget="_blank" href="/search/%E7%BD%91%E7%BB%9C%E7%BC%96%E7%A8%8B/1.htm">网络编程</a> <div>介绍Django为多种数据库后台提供了统一的调用API,在Django的帮助下,我们不用直接编写SQL语句。Django将关系型的表(table)转换成为一个类(class)。而每个记录(record)是该类下的一个对象(object)。我们可以使用基于对象的方法,来操纵关系型数据库。设置数据库设置数据库需要修改settings.py文件如果使用的数据库是mysql:[python]viewpla</div> </li> <li><a href="/article/1890751447600001024.htm" title="青少年编程与数学 02-009 Django 5 Web 编程 06课题、模型定义" target="_blank">青少年编程与数学 02-009 Django 5 Web 编程 06课题、模型定义</a> <span class="text-muted">明月看潮生</span> <a class="tag" taget="_blank" href="/search/%E7%BC%96%E7%A8%8B%E4%B8%8E%E6%95%B0%E5%AD%A6/1.htm">编程与数学</a><a class="tag" taget="_blank" href="/search/%E7%AC%AC02%E9%98%B6%E6%AE%B5/1.htm">第02阶段</a><a class="tag" taget="_blank" href="/search/%E9%9D%92%E5%B0%91%E5%B9%B4%E7%BC%96%E7%A8%8B/1.htm">青少年编程</a><a class="tag" taget="_blank" href="/search/django/1.htm">django</a><a class="tag" taget="_blank" href="/search/python/1.htm">python</a><a class="tag" taget="_blank" href="/search/%E7%BC%96%E7%A8%8B%E4%B8%8E%E6%95%B0%E5%AD%A6/1.htm">编程与数学</a> <div>青少年编程与数学02-009Django5Web编程06课题、模型定义一、模型二、定义模型1.导入模型类2.定义模型类3.定义字段4.添加元数据(可选)5.定义模型方法(可选)6.迁移模型三、模型字段字符字段数字字段日期和时间字段布尔字段关系字段文件字段其他字段四、主键和索引添加主键添加索引注意事项五、外键定义外键字段`on_delete`参数其他参数示例六、关系1.一对一关系(One-to-On</div> </li> <li><a href="/article/1890738084954304512.htm" title="Python Web开发记录 Day12:Django part6 用户登录" target="_blank">Python Web开发记录 Day12:Django part6 用户登录</a> <span class="text-muted">Code_流苏</span> <a class="tag" taget="_blank" href="/search/%23/1.htm">#</a><a class="tag" taget="_blank" href="/search/---Python/1.htm">---Python</a><a class="tag" taget="_blank" href="/search/Web%E5%BC%80%E5%8F%91---/1.htm">Web开发---</a><a class="tag" taget="_blank" href="/search/%23/1.htm">#</a><a class="tag" taget="_blank" href="/search/Django/1.htm">Django</a><a class="tag" taget="_blank" href="/search/%E9%A1%B9%E7%9B%AE%E6%8E%A2%E7%B4%A2%E5%AE%9E%E9%AA%8C%E5%AE%A4/1.htm">项目探索实验室</a><a class="tag" taget="_blank" href="/search/python/1.htm">python</a><a class="tag" taget="_blank" href="/search/%E5%89%8D%E7%AB%AF/1.htm">前端</a><a class="tag" taget="_blank" href="/search/django/1.htm">django</a> <div>名人说:东边日出西边雨,道是无晴却有晴。——刘禹锡《竹枝词》创作者:Code_流苏(CSDN)(一个喜欢古诗词和编程的Coder)目录1、登录界面2、用户名密码校验3、cookie与session配置①cookie与session②配置4、登录验证5、注销登录6、图片验证码①Pillow库②图片验证码的实现7、补充:图片验证码的作用和扩展①作用②其他类型的验证码8、验证码校验在上一篇博客中我们实现</div> </li> <li><a href="/article/1890563681683566592.htm" title="21 - 富文本框" target="_blank">21 - 富文本框</a> <span class="text-muted">一个微不足道的bug</span> <a class="tag" taget="_blank" href="/search/Django/1.htm">Django</a><a class="tag" taget="_blank" href="/search/django/1.htm">django</a> <div>富文本框:一般用于写文章,编辑内容自带样式官网:https://pypi.org/project/django-tinymce/1.安装第三方库pipinstalldjango-tinymce-ihttps://pypi.tuna.tsinghua.edu.cn/simple/2.settings.py注册和配置编辑器#注册编辑器INSTALLED_APPS=[..."tinymce",]#富文本</div> </li> <li><a href="/article/1890520172091994112.htm" title="python虚拟环境激活" target="_blank">python虚拟环境激活</a> <span class="text-muted">修福泥</span> <a class="tag" taget="_blank" href="/search/python/1.htm">python</a><a class="tag" taget="_blank" href="/search/%E5%BC%80%E5%8F%91%E8%AF%AD%E8%A8%80/1.htm">开发语言</a> <div>条件:python解释器里已经安装了Django,虚拟环境开启后报错报错:ImportError:Couldn'timportDjango.Areyousureit'sinstalledandavailableonyourPYTHONPATHenvironmentvariable?Didyouforgettoactivateavirtualenvironment?(new)C:\Users\666</div> </li> <li><a href="/article/1890496086653595648.htm" title="Django JSON-RPC 项目常见问题解决方案" target="_blank">Django JSON-RPC 项目常见问题解决方案</a> <span class="text-muted">魏纯漫</span> <div>DjangoJSON-RPC项目常见问题解决方案django-json-rpcJSON-RPCImplementationforDjango项目地址:https://gitcode.com/gh_mirrors/dj/django-json-rpc项目基础介绍DjangoJSON-RPC是一个为Django框架提供JSON-RPC实现的开源项目。JSON-RPC是一种轻量级的远程过程调用协议,通过</div> </li> <li><a href="/article/1890475646191202304.htm" title="Python基于Django的漏洞扫描系统【附源码、文档说明】" target="_blank">Python基于Django的漏洞扫描系统【附源码、文档说明】</a> <span class="text-muted">Java老徐</span> <a class="tag" taget="_blank" href="/search/Python/1.htm">Python</a><a class="tag" taget="_blank" href="/search/%E6%AF%95%E4%B8%9A%E8%AE%BE%E8%AE%A1/1.htm">毕业设计</a><a class="tag" taget="_blank" href="/search/python/1.htm">python</a><a class="tag" taget="_blank" href="/search/django/1.htm">django</a><a class="tag" taget="_blank" href="/search/%E6%BC%8F%E6%B4%9E%E6%89%AB%E6%8F%8F%E7%B3%BB%E7%BB%9F/1.htm">漏洞扫描系统</a><a class="tag" taget="_blank" href="/search/%E6%BC%8F%E6%B4%9E%E6%89%AB%E6%8F%8F/1.htm">漏洞扫描</a><a class="tag" taget="_blank" href="/search/Python%E6%BC%8F%E6%B4%9E%E6%89%AB%E6%8F%8F%E7%B3%BB%E7%BB%9F/1.htm">Python漏洞扫描系统</a><a class="tag" taget="_blank" href="/search/Python/1.htm">Python</a><a class="tag" taget="_blank" href="/search/Django/1.htm">Django</a> <div>博主介绍:✌Java老徐、7年大厂程序员经历。全网粉丝12w+、csdn博客专家、掘金/华为云/阿里云/InfoQ等平台优质作者、专注于Java技术领域和毕业项目实战✌文末获取源码联系精彩专栏推荐订阅不然下次找不到哟2024-2025年Java毕业设计选题推荐Python基于Django的微博热搜、微博舆论可视化系统(V3.0)基于PythonDjango的北极星招聘数据可视化系统感兴趣的可以先收</div> </li> <li><a href="/article/1890330254921232384.htm" title="Flask和Django相比哪个更适合新手?" target="_blank">Flask和Django相比哪个更适合新手?</a> <span class="text-muted">大懒猫软件</span> <a class="tag" taget="_blank" href="/search/python%E6%8A%80%E6%9C%AF%E5%AD%A6%E4%B9%A0/1.htm">python技术学习</a><a class="tag" taget="_blank" href="/search/flask/1.htm">flask</a><a class="tag" taget="_blank" href="/search/django/1.htm">django</a><a class="tag" taget="_blank" href="/search/sqlite/1.htm">sqlite</a> <div>Flask与Django:哪个更适合新手?对于新手来说,选择Flask还是Django主要取决于你的具体需求和项目复杂度。以下是两者的详细对比,帮助你做出选择:1.Flask优点简单易用:Flask是一个轻量级的微框架,代码简洁,易于理解和上手。适合初学者快速入门。灵活性高:Flask提供了高度的灵活性,开发者可以根据需要选择和集成各种扩展。适合小型项目:对于小型项目、原型开发和微服务,Flask</div> </li> <li><a href="/article/1890233429555998720.htm" title="青少年编程与数学 02-009 Django 5 Web 编程 13课题、URL分发" target="_blank">青少年编程与数学 02-009 Django 5 Web 编程 13课题、URL分发</a> <span class="text-muted">明月看潮生</span> <a class="tag" taget="_blank" href="/search/%E7%BC%96%E7%A8%8B%E4%B8%8E%E6%95%B0%E5%AD%A6/1.htm">编程与数学</a><a class="tag" taget="_blank" href="/search/%E7%AC%AC02%E9%98%B6%E6%AE%B5/1.htm">第02阶段</a><a class="tag" taget="_blank" href="/search/%E9%9D%92%E5%B0%91%E5%B9%B4%E7%BC%96%E7%A8%8B/1.htm">青少年编程</a><a class="tag" taget="_blank" href="/search/django/1.htm">django</a><a class="tag" taget="_blank" href="/search/%E7%BC%96%E7%A8%8B%E4%B8%8E%E6%95%B0%E5%AD%A6/1.htm">编程与数学</a><a class="tag" taget="_blank" href="/search/python/1.htm">python</a> <div>青少年编程与数学02-009Django5Web编程13课题、URL分发一、URL1.协议(Scheme)2.域名(Domain)3.端口号(Port)4.路径(Path)5.查询字符串(QueryString)6.锚点(Fragment)示例URL二、URL分发1.URL配置文件(urls.py)示例:项目的主`urls.py`示例:应用的`urls.py`2.URL模式(URLPatterns</div> </li> <li><a href="/article/1890222577155108864.htm" title="linux时间后mvt,Django MVT架构" target="_blank">linux时间后mvt,Django MVT架构</a> <span class="text-muted">经略幽燕我童贯</span> <a class="tag" taget="_blank" href="/search/linux%E6%97%B6%E9%97%B4%E5%90%8Emvt/1.htm">linux时间后mvt</a> <div>Web框架中的一些概念MVC大部分开发语言中都有MVC框架MVC框架的核心思想是:解耦降低各功能模块之间的耦合性,方便变更,更容易重构代码,最大程度上实现代码的重用m表示model模型,主要用于对数据库层的封装,对数据库的数据进项各种操作v表示view视图,用于对数据的展示层操作,负责模板页面的展示c表示controller控制器,用于对业务逻辑层操作,用于处理请求、获取数据、返回结果MVTDja</div> </li> <li><a href="/article/1890218036825223168.htm" title="django入门到精通三部曲(第一部)" target="_blank">django入门到精通三部曲(第一部)</a> <span class="text-muted">玉江仙。</span> <a class="tag" taget="_blank" href="/search/Django%E5%85%A5%E9%97%A8%E5%88%B0%E5%85%A5%E5%9C%9F/1.htm">Django入门到入土</a><a class="tag" taget="_blank" href="/search/django/1.htm">django</a><a class="tag" taget="_blank" href="/search/python/1.htm">python</a><a class="tag" taget="_blank" href="/search/%E5%90%8E%E7%AB%AF/1.htm">后端</a> <div>第一章:Django入门注意,第一章是开发基础,第二章是高级开发必备,第三章是项目实战,如果要进行第三章实战开发,必须熟练掌握第一章第二章,如有问题自行百度1.1Django简介Django简介MVC/MVT设计模式Django的优势和缺点Django简介Django是一个使用Python编程语言开发的开源Web框架,它遵循了MVC(Model-View-Controller)或者更准确地说是MV</div> </li> <li><a href="/article/1890211732337520640.htm" title="青少年编程与数学 02-009 Django 5 Web 编程 11课题、模板系统" target="_blank">青少年编程与数学 02-009 Django 5 Web 编程 11课题、模板系统</a> <span class="text-muted">明月看潮生</span> <a class="tag" taget="_blank" href="/search/%E7%BC%96%E7%A8%8B%E4%B8%8E%E6%95%B0%E5%AD%A6/1.htm">编程与数学</a><a class="tag" taget="_blank" href="/search/%E7%AC%AC02%E9%98%B6%E6%AE%B5/1.htm">第02阶段</a><a class="tag" taget="_blank" href="/search/%E9%9D%92%E5%B0%91%E5%B9%B4%E7%BC%96%E7%A8%8B/1.htm">青少年编程</a><a class="tag" taget="_blank" href="/search/django/1.htm">django</a><a class="tag" taget="_blank" href="/search/python/1.htm">python</a><a class="tag" taget="_blank" href="/search/%E7%BC%96%E7%A8%8B%E4%B8%8E%E6%95%B0%E5%AD%A6/1.htm">编程与数学</a> <div>青少年编程与数学02-009Django5Web编程11课题、模板系统一、模板1.模板的基本概念2.模板的加载和渲染3.模板继承4.自定义模板标签和过滤器5.模板的配置和优化二、模板标签基本用法常用模板标签控制流标签模板加载标签模板控制标签自定义模板标签三、模板过滤器基本用法内置过滤器字符串过滤器日期和时间过滤器列表过滤器自定义过滤器过滤器的注意事项四、模板配置基本配置配置选项详解`BACKEND</div> </li> <li><a href="/article/1890208707061542912.htm" title="Django 创建第一个项目" target="_blank">Django 创建第一个项目</a> <span class="text-muted">wjs2024</span> <a class="tag" taget="_blank" href="/search/%E5%BC%80%E5%8F%91%E8%AF%AD%E8%A8%80/1.htm">开发语言</a> <div>Django创建第一个项目引言Django是一个高级的PythonWeb框架,它鼓励快速开发和干净、实用的设计。本指南将带您从头开始创建一个简单的Django项目,以便您能够熟悉Django的基本结构和概念。准备工作在开始之前,请确保您已经安装了Python和Django。以下是安装步骤:安装Python:Django需要Python3.6或更高版本。您可以从Python官网下载并安装。安装Dja</div> </li> <li><a href="/article/1890204168627482624.htm" title="青少年编程与数学 02-009 Django 5 Web 编程 12课题、表单处理" target="_blank">青少年编程与数学 02-009 Django 5 Web 编程 12课题、表单处理</a> <span class="text-muted">明月看潮生</span> <a class="tag" taget="_blank" href="/search/%E7%BC%96%E7%A8%8B%E4%B8%8E%E6%95%B0%E5%AD%A6/1.htm">编程与数学</a><a class="tag" taget="_blank" href="/search/%E7%AC%AC02%E9%98%B6%E6%AE%B5/1.htm">第02阶段</a><a class="tag" taget="_blank" href="/search/%E9%9D%92%E5%B0%91%E5%B9%B4%E7%BC%96%E7%A8%8B/1.htm">青少年编程</a><a class="tag" taget="_blank" href="/search/django/1.htm">django</a><a class="tag" taget="_blank" href="/search/%E7%BC%96%E7%A8%8B%E4%B8%8E%E6%95%B0%E5%AD%A6/1.htm">编程与数学</a><a class="tag" taget="_blank" href="/search/python/1.htm">python</a> <div>青少年编程与数学02-009Django5Web编程12课题、表单处理一、表单1.表单类的定义示例:普通表单示例:模型表单2.字段类型3.验证4.渲染5.表单处理示例:视图中的表单处理6.自定义表单二、验证1.字段级验证示例2.表单级验证示例3.自定义验证器示例4.使用表单的`is_valid()`方法示例三、验证失败1.显示清晰的错误信息2.使用前端验证3.保留用户输入4.提供友好的错误提示样式</div> </li> <li><a href="/article/55.htm" title="多线程编程之卫生间" target="_blank">多线程编程之卫生间</a> <span class="text-muted">周凡杨</span> <a class="tag" taget="_blank" href="/search/java/1.htm">java</a><a class="tag" taget="_blank" href="/search/%E5%B9%B6%E5%8F%91/1.htm">并发</a><a class="tag" taget="_blank" href="/search/%E5%8D%AB%E7%94%9F%E9%97%B4/1.htm">卫生间</a><a class="tag" taget="_blank" href="/search/%E7%BA%BF%E7%A8%8B/1.htm">线程</a><a class="tag" taget="_blank" href="/search/%E5%8E%95%E6%89%80/1.htm">厕所</a> <div>如大家所知,火车上车厢的卫生间很小,每次只能容纳一个人,一个车厢只有一个卫生间,这个卫生间会被多个人同时使用,在实际使用时,当一个人进入卫生间时则会把卫生间锁上,等出来时打开门,下一个人进去把门锁上,如果有一个人在卫生间内部则别人的人发现门是锁的则只能在外面等待。问题分析:首先问题中有两个实体,一个是人,一个是厕所,所以设计程序时就可以设计两个类。人是多数的,厕所只有一个(暂且模拟的是一个车厢)。</div> </li> <li><a href="/article/182.htm" title="How to Install GUI to Centos Minimal" target="_blank">How to Install GUI to Centos Minimal</a> <span class="text-muted">sunjing</span> <a class="tag" taget="_blank" href="/search/linux/1.htm">linux</a><a class="tag" taget="_blank" href="/search/Install/1.htm">Install</a><a class="tag" taget="_blank" href="/search/Desktop/1.htm">Desktop</a><a class="tag" taget="_blank" href="/search/GUI/1.htm">GUI</a> <div>http://www.namhuy.net/475/how-to-install-gui-to-centos-minimal.html   I have centos 6.3 minimal running as web server. I’m looking to install gui to my server to vnc to my server. You can insta</div> </li> <li><a href="/article/309.htm" title="Shell 函数" target="_blank">Shell 函数</a> <span class="text-muted">daizj</span> <a class="tag" taget="_blank" href="/search/shell/1.htm">shell</a><a class="tag" taget="_blank" href="/search/%E5%87%BD%E6%95%B0/1.htm">函数</a> <div>Shell 函数 linux shell 可以用户定义函数,然后在shell脚本中可以随便调用。 shell中函数的定义格式如下: [function] funname [()]{ action; [return int;] } 说明: 1、可以带function fun() 定义,也可以直接fun() 定义,不带任何参数。 2、参数返回</div> </li> <li><a href="/article/436.htm" title="Linux服务器新手操作之一" target="_blank">Linux服务器新手操作之一</a> <span class="text-muted">周凡杨</span> <a class="tag" taget="_blank" href="/search/Linux+%E7%AE%80%E5%8D%95+%E6%93%8D%E4%BD%9C/1.htm">Linux 简单 操作</a> <div>1.whoami      当一个用户登录Linux系统之后,也许他想知道自己是发哪个用户登录的。      此时可以使用whoami命令。      [ecuser@HA5-DZ05 ~]$ whoami       e</div> </li> <li><a href="/article/563.htm" title="浅谈Socket通信(一)" target="_blank">浅谈Socket通信(一)</a> <span class="text-muted">朱辉辉33</span> <a class="tag" taget="_blank" href="/search/socket/1.htm">socket</a> <div>在java中ServerSocket用于服务器端,用来监听端口。通过服务器监听,客户端发送请求,双方建立链接后才能通信。当服务器和客户端建立链接后,两边都会产生一个Socket实例,我们可以通过操作Socket来建立通信。    首先我建立一个ServerSocket对象。当然要导入java.net.ServerSocket包    ServerSock</div> </li> <li><a href="/article/690.htm" title="关于框架的简单认识" target="_blank">关于框架的简单认识</a> <span class="text-muted">西蜀石兰</span> <a class="tag" taget="_blank" href="/search/%E6%A1%86%E6%9E%B6/1.htm">框架</a> <div>入职两个月多,依然是一个不会写代码的小白,每天的工作就是看代码,写wiki。 前端接触CSS、HTML、JS等语言,一直在用的CS模型,自然免不了数据库的链接及使用,真心涉及框架,项目中用到的BootStrap算一个吧,哦,JQuery只能算半个框架吧,我更觉得它是另外一种语言。 后台一直是纯Java代码,涉及的框架是Quzrtz和log4j。 都说学前端的要知道三大框架,目前node.</div> </li> <li><a href="/article/817.htm" title="You have an error in your SQL syntax; check the manual that corresponds to your" target="_blank">You have an error in your SQL syntax; check the manual that corresponds to your</a> <span class="text-muted">林鹤霄</span> <div>You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'option,changed_ids  ) values('0ac91f167f754c8cbac00e9e3dc372</div> </li> <li><a href="/article/944.htm" title="MySQL5.6的my.ini配置" target="_blank">MySQL5.6的my.ini配置</a> <span class="text-muted">aigo</span> <a class="tag" taget="_blank" href="/search/mysql/1.htm">mysql</a> <div>注意:以下配置的服务器硬件是:8核16G内存    [client]   port=3306   [mysql]   default-character-set=utf8     [mysqld]   port=3306   basedir=D:/mysql-5.6.21-win</div> </li> <li><a href="/article/1071.htm" title="mysql 全文模糊查找 便捷解决方案" target="_blank">mysql 全文模糊查找 便捷解决方案</a> <span class="text-muted">alxw4616</span> <a class="tag" taget="_blank" href="/search/mysql/1.htm">mysql</a> <div>mysql 全文模糊查找 便捷解决方案 2013/6/14 by 半仙 alxw4616@Msn.com 目的: 项目需求实现模糊查找. 原则: 查询不能超过 1秒. 问题: 目标表中有超过1千万条记录. 使用like '%str%' 进行模糊查询无法达到性能需求. 解决方案: 使用mysql全文索引. 1.全文索引 : MySQL支持全文索引和搜索功能。MySQL中的全文索</div> </li> <li><a href="/article/1198.htm" title="自定义数据结构 链表(单项 ,双向,环形)" target="_blank">自定义数据结构 链表(单项 ,双向,环形)</a> <span class="text-muted">百合不是茶</span> <a class="tag" taget="_blank" href="/search/%E5%8D%95%E9%A1%B9%E9%93%BE%E8%A1%A8/1.htm">单项链表</a><a class="tag" taget="_blank" href="/search/%E5%8F%8C%E5%90%91%E9%93%BE%E8%A1%A8/1.htm">双向链表</a> <div>     链表与动态数组的实现方式差不多,    数组适合快速删除某个元素    链表则可以快速的保存数组并且可以是不连续的       单项链表;数据从第一个指向最后一个   实现代码:        //定义动态链表 clas</div> </li> <li><a href="/article/1325.htm" title="threadLocal实例" target="_blank">threadLocal实例</a> <span class="text-muted">bijian1013</span> <a class="tag" taget="_blank" href="/search/java/1.htm">java</a><a class="tag" taget="_blank" href="/search/thread/1.htm">thread</a><a class="tag" taget="_blank" href="/search/java%E5%A4%9A%E7%BA%BF%E7%A8%8B/1.htm">java多线程</a><a class="tag" taget="_blank" href="/search/threadLocal/1.htm">threadLocal</a> <div>实例1: package com.bijian.thread; public class MyThread extends Thread { private static ThreadLocal tl = new ThreadLocal() { protected synchronized Object initialValue() { return new Inte</div> </li> <li><a href="/article/1452.htm" title="activemq安全设置—设置admin的用户名和密码" target="_blank">activemq安全设置—设置admin的用户名和密码</a> <span class="text-muted">bijian1013</span> <a class="tag" taget="_blank" href="/search/java/1.htm">java</a><a class="tag" taget="_blank" href="/search/activemq/1.htm">activemq</a> <div>        ActiveMQ使用的是jetty服务器, 打开conf/jetty.xml文件,找到 <bean id="adminSecurityConstraint" class="org.eclipse.jetty.util.security.Constraint"> <p</div> </li> <li><a href="/article/1579.htm" title="【Java范型一】Java范型详解之范型集合和自定义范型类" target="_blank">【Java范型一】Java范型详解之范型集合和自定义范型类</a> <span class="text-muted">bit1129</span> <a class="tag" taget="_blank" href="/search/java/1.htm">java</a> <div>本文详细介绍Java的范型,写一篇关于范型的博客原因有两个,前几天要写个范型方法(返回值根据传入的类型而定),竟然想了半天,最后还是从网上找了个范型方法的写法;再者,前一段时间在看Gson, Gson这个JSON包的精华就在于对范型的优雅简单的处理,看它的源代码就比较迷糊,只其然不知其所以然。所以,还是花点时间系统的整理总结下范型吧。   范型内容 范型集合类 范型类 </div> </li> <li><a href="/article/1706.htm" title="【HBase十二】HFile存储的是一个列族的数据" target="_blank">【HBase十二】HFile存储的是一个列族的数据</a> <span class="text-muted">bit1129</span> <a class="tag" taget="_blank" href="/search/hbase/1.htm">hbase</a> <div>在HBase中,每个HFile存储的是一个表中一个列族的数据,也就是说,当一个表中有多个列簇时,针对每个列簇插入数据,最后产生的数据是多个HFile,每个对应一个列族,通过如下操作验证   1. 建立一个有两个列族的表   create 'members','colfam1','colfam2'   2. 在members表中的colfam1中插入50*5</div> </li> <li><a href="/article/1833.htm" title="Nginx 官方一个配置实例" target="_blank">Nginx 官方一个配置实例</a> <span class="text-muted">ronin47</span> <a class="tag" taget="_blank" href="/search/nginx+%E9%85%8D%E7%BD%AE%E5%AE%9E%E4%BE%8B/1.htm">nginx 配置实例</a> <div>user www www; worker_processes 5; error_log logs/error.log; pid logs/nginx.pid; worker_rlimit_nofile 8192; events { worker_connections 4096;} http { include conf/mim</div> </li> <li><a href="/article/1960.htm" title="java-15.输入一颗二元查找树,将该树转换为它的镜像, 即在转换后的二元查找树中,左子树的结点都大于右子树的结点。 用递归和循环" target="_blank">java-15.输入一颗二元查找树,将该树转换为它的镜像, 即在转换后的二元查找树中,左子树的结点都大于右子树的结点。 用递归和循环</a> <span class="text-muted">bylijinnan</span> <a class="tag" taget="_blank" href="/search/java/1.htm">java</a> <div> //use recursion public static void mirrorHelp1(Node node){ if(node==null)return; swapChild(node); mirrorHelp1(node.getLeft()); mirrorHelp1(node.getRight()); } //use no recursion bu</div> </li> <li><a href="/article/2087.htm" title="返回null还是empty" target="_blank">返回null还是empty</a> <span class="text-muted">bylijinnan</span> <a class="tag" taget="_blank" href="/search/java/1.htm">java</a><a class="tag" taget="_blank" href="/search/apache/1.htm">apache</a><a class="tag" taget="_blank" href="/search/spring/1.htm">spring</a><a class="tag" taget="_blank" href="/search/%E7%BC%96%E7%A8%8B/1.htm">编程</a> <div>第一个问题,函数是应当返回null还是长度为0的数组(或集合)? 第二个问题,函数输入参数不当时,是异常还是返回null? 先看第一个问题 有两个约定我觉得应当遵守: 1.返回零长度的数组或集合而不是null(详见《Effective Java》) 理由就是,如果返回empty,就可以少了很多not-null判断: List<Person> list</div> </li> <li><a href="/article/2214.htm" title="[科技与项目]工作流厂商的战略机遇期" target="_blank">[科技与项目]工作流厂商的战略机遇期</a> <span class="text-muted">comsci</span> <a class="tag" taget="_blank" href="/search/%E5%B7%A5%E4%BD%9C%E6%B5%81/1.htm">工作流</a> <div>       在新的战略平衡形成之前,这里有一个短暂的战略机遇期,只有大概最短6年,最长14年的时间,这段时间就好像我们森林里面的小动物,在秋天中,必须抓紧一切时间存储坚果一样,否则无法熬过漫长的冬季。。。。         在微软,甲骨文,谷歌,IBM,SONY</div> </li> <li><a href="/article/2341.htm" title="过度设计-举例" target="_blank">过度设计-举例</a> <span class="text-muted">cuityang</span> <a class="tag" taget="_blank" href="/search/%E8%BF%87%E5%BA%A6%E8%AE%BE%E8%AE%A1/1.htm">过度设计</a> <div>过度设计,需要更多设计时间和测试成本,如无必要,还是尽量简洁一些好。 未来的事情,比如 访问量,比如数据库的容量,比如是否需要改成分布式  都是无法预料的 再举一个例子,对闰年的判断逻辑:   1、 if($Year%4==0) return True; else return Fasle;   2、if (   ($Year%4==0  &am</div> </li> <li><a href="/article/2468.htm" title="java进阶,《Java性能优化权威指南》试读" target="_blank">java进阶,《Java性能优化权威指南》试读</a> <span class="text-muted">darkblue086</span> <a class="tag" taget="_blank" href="/search/java%E6%80%A7%E8%83%BD%E4%BC%98%E5%8C%96/1.htm">java性能优化</a> <div>记得当年随意读了微软出版社的.NET 2.0应用程序调试,才发现调试器如此强大,应用程序开发调试其实真的简单了很多,不仅仅是因为里面介绍了很多调试器工具的使用,更是因为里面寻找问题并重现问题的思想让我震撼,时隔多年,Java已经如日中天,成为许多大型企业应用的首选,而今天,这本《Java性能优化权威指南》让我再次找到了这种感觉,从不经意的开发过程让我刮目相看,原来性能调优不是简单地看看热点在哪里,</div> </li> <li><a href="/article/2595.htm" title="网络学习笔记初识OSI七层模型与TCP协议" target="_blank">网络学习笔记初识OSI七层模型与TCP协议</a> <span class="text-muted">dcj3sjt126com</span> <a class="tag" taget="_blank" href="/search/%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0/1.htm">学习笔记</a> <div>  协议:在计算机网络中通信各方面所达成的、共同遵守和执行的一系列约定   计算机网络的体系结构:计算机网络的层次结构和各层协议的集合。   两类服务:   面向连接的服务通信双方在通信之前先建立某种状态,并在通信过程中维持这种状态的变化,同时为服务对象预先分配一定的资源。这种服务叫做面向连接的服务。   面向无连接的服务通信双方在通信前后不建立和维持状态,不为服务对象</div> </li> <li><a href="/article/2722.htm" title="mac中用命令行运行mysql" target="_blank">mac中用命令行运行mysql</a> <span class="text-muted">dcj3sjt126com</span> <a class="tag" taget="_blank" href="/search/mysql/1.htm">mysql</a><a class="tag" taget="_blank" href="/search/linux/1.htm">linux</a><a class="tag" taget="_blank" href="/search/mac/1.htm">mac</a> <div>参考这篇博客:http://www.cnblogs.com/macro-cheng/archive/2011/10/25/mysql-001.html  感觉workbench不好用(有点先入为主了)。 1,安装mysql 在mysql的官方网站下载 mysql 5.5.23 http://www.mysql.com/downloads/mysql/,根据我的机器的配置情况选择了64</div> </li> <li><a href="/article/2849.htm" title="MongDB查询(1)——基本查询[五]" target="_blank">MongDB查询(1)——基本查询[五]</a> <span class="text-muted">eksliang</span> <a class="tag" taget="_blank" href="/search/mongodb/1.htm">mongodb</a><a class="tag" taget="_blank" href="/search/mongodb+%E6%9F%A5%E8%AF%A2/1.htm">mongodb 查询</a><a class="tag" taget="_blank" href="/search/mongodb+find/1.htm">mongodb find</a> <div>MongDB查询 转载请出自出处:http://eksliang.iteye.com/blog/2174452 一、find简介 MongoDB中使用find来进行查询。 API:如下 function ( query , fields , limit , skip, batchSize, options ){.....}  参数含义: query:查询参数 fie</div> </li> <li><a href="/article/2976.htm" title="base64,加密解密 经融加密,对接" target="_blank">base64,加密解密 经融加密,对接</a> <span class="text-muted">y806839048</span> <a class="tag" taget="_blank" href="/search/%E7%BB%8F%E8%9E%8D%E5%8A%A0%E5%AF%86/1.htm">经融加密</a><a class="tag" taget="_blank" href="/search/%E5%AF%B9%E6%8E%A5/1.htm">对接</a> <div>String data0 = new String(Base64.encode(bo.getPaymentResult().getBytes(("GBK")))); String data1 = new String(Base64.decode(data0.toCharArray()),"GBK"); // 注意编码格式,注意用于加密,解密的要是同</div> </li> <li><a href="/article/3103.htm" title="JavaWeb之JSP概述" target="_blank">JavaWeb之JSP概述</a> <span class="text-muted">ihuning</span> <a class="tag" taget="_blank" href="/search/javaweb/1.htm">javaweb</a> <div>  什么是JSP?为什么使用JSP? JSP表示Java Server Page,即嵌有Java代码的HTML页面。使用JSP是因为在HTML中嵌入Java代码比在Java代码中拼接字符串更容易、更方便和更高效。   JSP起源    在很多动态网页中,绝大部分内容都是固定不变的,只有局部内容需要动态产生和改变。  如果使用Servl</div> </li> <li><a href="/article/3230.htm" title="apple watch 指南" target="_blank">apple watch 指南</a> <span class="text-muted">啸笑天</span> <a class="tag" taget="_blank" href="/search/apple/1.htm">apple</a> <div>1. 文档 WatchKit Programming Guide(中译在线版 By @CocoaChina) 译文 译者 原文 概览 - 开始为 Apple Watch 进行开发 @星夜暮晨 Overview - Developing for Apple Watch 概览 - 配置 Xcode 项目 - Overview - Configuring Yo</div> </li> <li><a href="/article/3357.htm" title="java经典的基础题目" target="_blank">java经典的基础题目</a> <span class="text-muted">macroli</span> <a class="tag" taget="_blank" href="/search/java/1.htm">java</a><a class="tag" taget="_blank" href="/search/%E7%BC%96%E7%A8%8B/1.htm">编程</a> <div>1.列举出 10个JAVA语言的优势 a:免费,开源,跨平台(平台独立性),简单易用,功能完善,面向对象,健壮性,多线程,结构中立,企业应用的成熟平台, 无线应用 2.列举出JAVA中10个面向对象编程的术语 a:包,类,接口,对象,属性,方法,构造器,继承,封装,多态,抽象,范型 3.列举出JAVA中6个比较常用的包 Java.lang;java.util;java.io;java.sql;ja</div> </li> <li><a href="/article/3484.htm" title="你所不知道神奇的js replace正则表达式" target="_blank">你所不知道神奇的js replace正则表达式</a> <span class="text-muted">qiaolevip</span> <a class="tag" taget="_blank" href="/search/%E6%AF%8F%E5%A4%A9%E8%BF%9B%E6%AD%A5%E4%B8%80%E7%82%B9%E7%82%B9/1.htm">每天进步一点点</a><a class="tag" taget="_blank" href="/search/%E5%AD%A6%E4%B9%A0%E6%B0%B8%E6%97%A0%E6%AD%A2%E5%A2%83/1.htm">学习永无止境</a><a class="tag" taget="_blank" href="/search/%E7%BA%B5%E8%A7%82%E5%8D%83%E8%B1%A1/1.htm">纵观千象</a><a class="tag" taget="_blank" href="/search/regex/1.htm">regex</a> <div>var v = 'C9CFBAA3CAD0'; console.log(v); var arr = v.split(''); for (var i = 0; i < arr.length; i ++) { if (i % 2 == 0) arr[i] = '%' + arr[i]; } console.log(arr.join('')); console.log(v.r</div> </li> <li><a href="/article/3611.htm" title="[一起学Hive]之十五-分析Hive表和分区的统计信息(Statistics)" target="_blank">[一起学Hive]之十五-分析Hive表和分区的统计信息(Statistics)</a> <span class="text-muted">superlxw1234</span> <a class="tag" taget="_blank" href="/search/hive/1.htm">hive</a><a class="tag" taget="_blank" href="/search/hive%E5%88%86%E6%9E%90%E8%A1%A8/1.htm">hive分析表</a><a class="tag" taget="_blank" href="/search/hive%E7%BB%9F%E8%AE%A1%E4%BF%A1%E6%81%AF/1.htm">hive统计信息</a><a class="tag" taget="_blank" href="/search/hive+Statistics/1.htm">hive Statistics</a> <div>关键字:Hive统计信息、分析Hive表、Hive Statistics   类似于Oracle的分析表,Hive中也提供了分析表和分区的功能,通过自动和手动分析Hive表,将Hive表的一些统计信息存储到元数据中。   表和分区的统计信息主要包括:行数、文件数、原始数据大小、所占存储大小、最后一次操作时间等;   14.1 新表的统计信息 对于一个新创建</div> </li> <li><a href="/article/3738.htm" title="Spring Boot 1.2.5 发布" target="_blank">Spring Boot 1.2.5 发布</a> <span class="text-muted">wiselyman</span> <a class="tag" taget="_blank" href="/search/spring+boot/1.htm">spring boot</a> <div>    Spring Boot 1.2.5已在7月2日发布,现在可以从spring的maven库和maven中心库下载。   这个版本是一个维护的发布版,主要是一些修复以及将Spring的依赖提升至4.1.7(包含重要的安全修复)。   官方建议所有的Spring Boot用户升级这个版本。   项目首页 | 源</div> </li> </ul> </div> </div> </div> <div> <div class="container"> <div class="indexes"> <strong>按字母分类:</strong> <a href="/tags/A/1.htm" target="_blank">A</a><a href="/tags/B/1.htm" target="_blank">B</a><a href="/tags/C/1.htm" target="_blank">C</a><a href="/tags/D/1.htm" target="_blank">D</a><a href="/tags/E/1.htm" target="_blank">E</a><a href="/tags/F/1.htm" target="_blank">F</a><a href="/tags/G/1.htm" target="_blank">G</a><a href="/tags/H/1.htm" target="_blank">H</a><a href="/tags/I/1.htm" target="_blank">I</a><a href="/tags/J/1.htm" target="_blank">J</a><a href="/tags/K/1.htm" target="_blank">K</a><a href="/tags/L/1.htm" target="_blank">L</a><a href="/tags/M/1.htm" target="_blank">M</a><a href="/tags/N/1.htm" target="_blank">N</a><a href="/tags/O/1.htm" target="_blank">O</a><a href="/tags/P/1.htm" target="_blank">P</a><a href="/tags/Q/1.htm" target="_blank">Q</a><a href="/tags/R/1.htm" target="_blank">R</a><a href="/tags/S/1.htm" target="_blank">S</a><a href="/tags/T/1.htm" target="_blank">T</a><a href="/tags/U/1.htm" target="_blank">U</a><a href="/tags/V/1.htm" target="_blank">V</a><a href="/tags/W/1.htm" target="_blank">W</a><a href="/tags/X/1.htm" target="_blank">X</a><a href="/tags/Y/1.htm" target="_blank">Y</a><a href="/tags/Z/1.htm" target="_blank">Z</a><a href="/tags/0/1.htm" target="_blank">其他</a> </div> </div> </div> <footer id="footer" class="mb30 mt30"> <div class="container"> <div class="footBglm"> <a target="_blank" href="/">首页</a> - <a target="_blank" href="/custom/about.htm">关于我们</a> - <a target="_blank" href="/search/Java/1.htm">站内搜索</a> - <a target="_blank" href="/sitemap.txt">Sitemap</a> - <a target="_blank" href="/custom/delete.htm">侵权投诉</a> </div> <div class="copyright">版权所有 IT知识库 CopyRight © 2000-2050 E-COM-NET.COM , All Rights Reserved. <!-- <a href="https://beian.miit.gov.cn/" rel="nofollow" target="_blank">京ICP备09083238号</a><br>--> </div> </div> </footer> <!-- 代码高亮 --> <script type="text/javascript" src="/static/syntaxhighlighter/scripts/shCore.js"></script> <script type="text/javascript" src="/static/syntaxhighlighter/scripts/shLegacy.js"></script> <script type="text/javascript" src="/static/syntaxhighlighter/scripts/shAutoloader.js"></script> <link type="text/css" rel="stylesheet" href="/static/syntaxhighlighter/styles/shCoreDefault.css"/> <script type="text/javascript" src="/static/syntaxhighlighter/src/my_start_1.js"></script> </body> </html>