首页 > 其他 > 详细

django加载模板文件

时间:2016-04-23 19:46:43      阅读:203      评论:0      收藏:0      [点我收藏+]

          views.py中编写相关代码

  • 第一种加载方式
from django.http import HttpResponse
from django.template import loader,Context

def index(req):
#生成模板对象
t=loader.get_template("index.html")
#生成Context对象
context = Context({})
return HttpResponse(t.render(context));
  • 第二种加载方式
from django.shortcuts import render_to_response
def index(req):
return render_to_response("index.html",{"title":"hello world","name":"JohnRey"})

django加载模板文件

原文:http://www.cnblogs.com/Yellow0-0River/p/5425161.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!