from django.conf.urls import url, include
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^hello/', include('hello.urls', namespace='qufen_include')), # 该include的命名空间
]
hello.urls.urlpatterns import reverse
urlpatterns = [
url(r'^loging/$', views.Login.as_view(), name='login'), # 反查 名称访问
]
使用 from django.shortcuts
class JumpPage(View): def get(self, request, num=''):
if num == '':
# return redirect('/hello/login/') # 普通跳转
# return redirect(reverse('login')) # url不带参数的反查
# return redirect(reverse('login:year', args=('2017', '02', '11'))) # 带非命名参数反查 命名空间+名称访问
return redirect(reverse('login:qufen_include:name', kwargs={'name': 'xiaoming'})) # 命名参数反查 命名空间 + 名称访问
else:
return HttpResponse('登录成功')