当前位置: 移动技术网 > IT编程>脚本编程>Python > Django框架模板注入操作示例【变量传递到模板】

Django框架模板注入操作示例【变量传递到模板】

2019年01月04日  | 移动技术网IT编程  | 我要评论

现在国务院总理是谁,苏州峰达集团,推广效果

本文实例讲述了django框架模板注入操作。分享给大家供大家参考,具体如下:

1.html模板如何解析变量?

<h1>这是一个html页面</h1>
<p>id:{{ user_id }}</p>
<p>名字:{{ username }}</p>

其中:{{变量名}}

2.如何传递数据到html模板上?

#coding:utf-8
from django.shortcuts import render,render_to_response
# create your views here.
from django.http import httpresponse
def hi(request):
  user = {'user_id':1,'username':'张三','username':'李四'}
  return render_to_response("",user)

user是定义的字典,键可以重复,同名键值打印最后添加的

3.最后模板效果

希望本文所述对大家基于django框架的python程序设计有所帮助。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网