urlpatterns = [
path('',include('front.urls')),
# 同一个app下有两个实例
path('cms1/',include('cms.urls',namespace='cms1')),
path('cms2/',include('cms.urls',namespace='cms2')),
]
以后在做反转的时候,就可以根据实例命名空间来指定具体的url。示例代码如下:
def index(request):
username = request.GET.get("username")
if username:
return HttpResponse('CMS首页')
else:
# 获取当前的命名空间
current_namespace = request.resolver_match.namespace
return redirect(reverse("%s:login" % current_namespace))