django html替换,django url和返回内容到html

文章思维导图

e0fdee97611a3424f66c5fb1ecca0557.png

nav.html, bottom.html, tongji.html

base.htmlhtml>

{% 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.pydef 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 %}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值