转发:只有一次请求和响应
render
render(request,template_name[,context])
结合一个给定的模板和一个给定的上下文字典,并返回一个渲染后的HttpResponse对象
request:该request用于生成response
template_name:要使用的模板的完整名称
context:添加到模板上下文的一个字典,视图将在渲染模板之前调用它
from django.shortcuts import render def index(request): return render(request,'booktest/index.html',{h1': hello'})
重定向:两对以上的请求和响应
redirect
redirect(to)
为传递进来的参数返回HttpResponseRedirect
to推荐使用反向解析
from django.shortcuts import redirect
from django.core.urlresolvers import reverse
def index(request):
return redirect(reverse('booktest:index2'))
注意
redirect(reverse(-----这里面写的是一个url ------))
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。