django加载本地html

from django.shortcuts import render

from django.http import HttpResponse
from django.shortcuts import render,render_to_response # Create your views here. def hello(request):
return render_to_response("hello.html")

传递数据到html中

Python代码

# Create your views here.
# http://weibo.com/lixiaodaoaaa class Person(object):
def __init__(self, name, age, sex):
self.name = name
self.age = age
self.sex = sex
def say(self):
return self.name def hello(request):
u_user = Person("dog", 18, "male")
myList = ["sendList to the html files", "god", "god02"]
u_content_dic = {"u_title": "Title Is Here", "u_user": u_user,"u_test_str":myList}
##传递一个字典作为Content_type
return render_to_response("hello.html", u_content_dic)

Html代码去取值:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>{{ u_title }}</title>
<h1>{{ u_user.age }}</h1>
<h1>{{ u_user.name }}</h1>
<h1>{{ u_user.sex}}</h1>
<h1>{{ u_test_str.0}}</h1>
<h1>{{ u_test_str.1}}</h1>
<br/>
<h1>{{ u_user.say}}</h1>
</head>
<body> </body>
</html>
原文 转自网络 年数久远 特此向作者致敬

最新文章

  1. Red Hat Enterprise Server 6.0 安装Sendmail相关包
  2. WPF学习之路(九)导航和页面(续)
  3. 在Mac mini上安装 ESXi 5.5
  4. 是否允许处理由Zend Encoder加密的PHP文件
  5. HDFS+MapReduce+Hive+HBase十分钟快速入门
  6. phpmailer 发送邮件
  7. CreateMutex
  8. js中的document.body.scrollTop与document.documentElement.scrollTop
  9. jenkins配置角色访问
  10. git笔记(1)-搭建
  11. 使用shell删除目录下几天前生成文件方法
  12. android有关生命周期探讨
  13. django -- model中只有Field类型的数据才能成为数据库中的列
  14. vue二级联动select
  15. 如何同步删除svn管理的package包目录
  16. python开发_logging_日志处理
  17. “Hello World!团队”Beta发布—视频链接+文案+美工
  18. Makefile-函数patsubst
  19. HDU3524 数论
  20. c++之默认参数的函数

热门文章

  1. LC 3. Longest Substring Without Repeating Characters
  2. 用Python获取计算机网卡信息
  3. Django 关联查询
  4. CentOS 7.X 静默安装Oracle 12C数据库
  5. Luogu4770 NOI2018你的名字(后缀自动机+线段树合并)
  6. C#类型转换工具类
  7. [异步请求]ajax、axios、fetch之间的详细区别以及优缺点
  8. SQL 删除重复记录,并保留其中一条
  9. 从零开始学ios开发(二):Hello World!
  10. R语言错误的提示(中英文翻译)