首页 > 其他 > 详细

django 标签

时间:2017-05-22 16:11:00      阅读:345      评论:0      收藏:0      [点我收藏+]

django标签

{% if/for/ifequal/ifnotequal condition %}

  ...{{ name|first|lower}}{# interpretation:lower the first word of name #}

{% endif/endfor/endifequal/ifnotequal %}

 

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

 

 将工程里的settings.py的DIRS修改为:

‘DIRS‘: [os.path.join(BASE_DIR, ‘templates‘)] ,

 

 以下内容在urls.py

from django.conf.urls import url from . import view urlpatterns = [url(r‘^$‘, view.django)]

 

 以下内容在view.html

from django.http import HttpResponse from django.shortcuts import render

def django(request):

    context = {}

    # context["question"] = u"aRe You OK?"

    # context["answer"] = u"i am fine,tks!"

    namelist = ["jackey","vickey"]

    context["namelist"] = namelist

    return render(request,‘testdjango.html‘,context)

 

 以下内容在hello.html的<body></body>标签对里

 {% extends "base.html" %}
    {% block mainbody %}
{#        <h1>{{ question|lower }}</h1>#}
{#        <h1>{{ answer|upper|truncatechars:"10" }}</h1>#}
        {% for name in namelist %}
            <ul>
            {% if name == "jackey" %}
                <li>{{ name }}</li>
            {% elif name == "vickey" %}
                <li>{{ name }}</li>
            {% else %}
                <li>{{ name }}</li>
            {% endif %}
            </ul>
        {% endfor %}
    {% endblock %}

django 标签

原文:http://www.cnblogs.com/vickey-wu/p/6889777.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!