Python Web框架Django模板标签

变量、列表及字典

(1)控制器

1
2
3
4
5
6
7
8
def appblog(request):
# context = {}
# context['hello'] = 'http://www.appblog.cn'
# return render(request, 'test.html', context)
views_var = 'http://www.appblog.cn' # 变量
views_list = ["AppBlog", "AliPay", "WeChat"] # 变量
views_dict = {"name": "APP开发技术博客"} # 字典
return render(request, 'test.html', {"hello": views_var, "views_list": views_list, "views_dict": views_dict})

(2)视图

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Hello</title>
</head>
<body>
<h1>{{ views_var }}</h1>

<p>{{ views_list }}</p>
<p>{{ views_list.0 }}</p>

<p>{{ views_dict }}</p>
<p>{{ views_dict.name }}</p>
</body>
</html>

Powered by AppBlog.CN     浙ICP备14037229号

Copyright © 2012 - 2020 APP开发技术博客 All Rights Reserved.

访客数 : | 访问量 :