模板有三种使用方法
views
from django.template import loader, Context, template from django.http import HttpResponse from django.shortcuts import render_tp_response def index1(req): t = loader.get_template(‘index.html‘) c = Context({‘usename‘:‘jlan‘}) return HttpResponse(t.render(c)) def index2(req): t = Tempate(‘<h1>hello, {{username}}</h1>‘) #创建模板 c = Context({‘username‘:‘jlan‘}) return HttpResponse(t.render(c)) def index3(req): return render_to_response(‘index.html‘, {‘username‘:‘jlan‘})
时间: 2024-10-26 13:17:55