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({"title":"hello world","name":"JohnRey"})return HttpResponse(t.render(context));
- 第二种加载方式
from django.shortcuts import render_to_responsedef index(req): return render_to_response("index.html",{"title":"hello world","name":"JohnRey"})