码迷,mamicode.com
首页 > 其他好文 > 详细

django加载模板文件

时间:2016-04-23 19:48:38      阅读:126      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!