zoukankan      html  css  js  c++  java
  • 边学边体验django

    django菜鸟入门连接:http://www.runoob.com/django/django-template.html

    安装以及Demo里面都有。

    我边学边在电脑上演示,然后发现一些和实际不一样的地方:

    1.Hello World, demo我电脑上跳出,不识别 patterns 错误。

     经过看看代码,我改成: urlpatterns.append(url('^hello/$',hello) 可以运行

    2. 添加template,用render 来渲染页面时。添加 template 的dir时,可以使用os.path.join(BASE_DIR,'templates') 做到。

       templates 文件夹应该放在manage.py同目录

    3.html 文档中,关键字 比如 {% if xxx  %}, 之间要有空格

    标签有:

      

    if/else 标签

    基本语法格式如下:

    {% if condition %}
         ... display
    {% endif %}

    或者:

    {% if condition1 %}
       ... display 1
    {% elif condiiton2 %}
       ... display 2
    {% else %}
       ... display 3
    {% endif %}


    {% if %} 标签接受 and , or 或者 not 关键字来对多个变量做判断 ,或者对变量取反( not )

    {% for athlete in athlete_list %}
        <li>{{ athlete.name }}</li>
    {% endfor %}


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

    {% ifequal user currentuser %}
        <h1>Welcome!</h1>
    {% endifequal %}

    ifnotequal

    {# 这是一个注释 #}


    {{ name|lower }}

    有些过滤器有参数。 过滤器的参数跟随冒号之后并且总是以双引号包含。 例如:

    {{ bio|truncatewords:"30" }}


    其他过滤器:

    • addslashes : 添加反斜杠到任何反斜杠、单引号或者双引号前面。
    • date : 按指定的格式字符串参数格式化 date 或者 datetime 对象,实例:
      {{ pub_date|date:"F j, Y" }}
    • length : 返回变量的长度。

     {% include %} 标签允许在模板中包含其它的模板的内容。

    继承:

     base 

    {% block  blockname %}

     ...

    {% endblock %}

    继承:

    {% extends 'basename.html' %}

    {% block blockname %}

      ...

    {% endblock}

    继承和Include的区别:

    继承是完成覆盖,我没有找到添加自己内容的方法
    Include可以添加自己的内容

     
     
     
  • 相关阅读:
    51nod1260
    51nod1327
    51nod1342
    51nod1479
    LOJ6088
    51nod1634
    51nod1778
    JAVA循环结构学校上机经常遇到的几题 笔记
    B. The Number of Products(Codeforces Round #585 (Div. 2))
    A. Yellow Cards ( Codeforces Round #585 (Div. 2) 思维水题
  • 原文地址:https://www.cnblogs.com/ahMay/p/5740905.html
Copyright © 2011-2022 走看看