djangourl和返回内容到html-创新互联
文章思维导图


nav.html, bottom.html, tongji.html
base.html
{% block title %}默认标题{% endblock %} - lanny教堂 {% include 'nav.html' %} //定义块,以后模版继承base后可以替换. {% block content %}这里是默认内容,所有继承自这个模板的,如果不覆盖就显示这里的默认内容。{% endblock %} {% include 'bottom.html' %} {% include 'tongji.html' %}
home.html继承且覆盖base
{% extends 'base.html' %}
{% block title %}欢迎光临首页{% endblock %}
{% block content %}
{% include 'ad.html' %}
这里是首页,欢迎光临
{% endblock %}包含语法
{% include 'bottom.html' %}
{% block content %}
{% include 'ad.html' %}
{% endblock %}字符串
views.py
def home(request):
string = u"我在lanny教堂学习Django,用它来建网站"
return render(request, 'home.html', {'string': string})
home.html
{{ string }}列表:
views.py
def home(request):
TutorialList = ["HTML", "CSS", "jQuery", "Python", "Django"]
return render(request, 'home.html', {'TutorialList': TutorialList})
在视图中我们传递了一个List到模板 home.html:
教程列表:
{% for i in TutorialList %}
{{ i }}
{% endfor %}home.html
教程列表:
{% for i in TutorialList %}
{{ i }}
{% endfor %}字典
views.py
def home(request):
info_dict = {'site': u'lanny教堂', 'content': u'各种IT技术教程'}
return render(request, 'home.html', {'info_dict': info_dict})
home.html法1:
站点:{{ info_dict.site }} 内容:{{ info_dict.content }}
法2:遍历
{% for key, value in info_dict.items %}
{{ key }}: {{ value }}
{% endfor %}另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。
新闻名称:djangourl和返回内容到html-创新互联
转载源于:http://www.scyingshan.cn/article/ddejgs.html


咨询
建站咨询
