在视图函数里面,如果你去直接通过response跳转url,是不可以,因为response只能返回参数列表
如果想要跳转页面,使用新的方法 HttpResponseRedirect
def text(request):
return HttpResponseRedirect('/App/hello/')
但是里面只能传固定地址值
如果想要通过动态获取(反向解析)的方式传参,需要新的方法 reverse() 导Django的包
def text(request):
return HttpResponseRedirect(reverse("fan:bingbing"))
反向解析配置:
在App目录下配置urls 需要给他一个name属性 name = "名字自定义":
例如:http://127.0.0.1:8080/App/getstudent/
url(r'^getstudent/',views.getstudent,name='game')
反向解析传参配置,即访问url时需带相应的正则匹配参数:
例如:http://127.0.0.1:8080/App/getstudent/2018/09/
l(r'^getstudent/(?P<year>\d+)/(?P<month>\d+)/',views.getstudent,name='game'):
相应的当浏览器访问url时,在Views层的写法如下