django加载本地html
2024-09-02 05:43:30
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>
原文 转自网络 年数久远 特此向作者致敬
最新文章
- Red Hat Enterprise Server 6.0 安装Sendmail相关包
- WPF学习之路(九)导航和页面(续)
- 在Mac mini上安装 ESXi 5.5
- 是否允许处理由Zend Encoder加密的PHP文件
- HDFS+MapReduce+Hive+HBase十分钟快速入门
- phpmailer 发送邮件
- CreateMutex
- js中的document.body.scrollTop与document.documentElement.scrollTop
- jenkins配置角色访问
- git笔记(1)-搭建
- 使用shell删除目录下几天前生成文件方法
- android有关生命周期探讨
- django -- model中只有Field类型的数据才能成为数据库中的列
- vue二级联动select
- 如何同步删除svn管理的package包目录
- python开发_logging_日志处理
- “Hello World!团队”Beta发布—视频链接+文案+美工
- Makefile-函数patsubst
- HDU3524 数论
- c++之默认参数的函数