django: url namespace

In the same django project, different app is likely to give the same name from the url.

Without doing anything, then all called the same name which one will use url url when called

For chestnut:

app01 the urls are:

urlpatterns=[path('',views.index,name='home'),
                   path('/login',views.login,name='login'),]                

app02 the urls are:

urlpatterns=[path('',views.index,name='home'),
                   path('/login',views.login,name='login'),]

urls under the project are:

urlpatterns=[path('app01/',include(app01.urls)),
                   path('app02/',include(app02.urls))]

 

Then the question came:

  views app01 app02 and are used in reserve to call upon login name = the url, are transferred to the following app02

How to do it?

The url namespace restrictions.

app01-urls:

app_name='app01'
urlpatterns=[path('',views.index,name='home'),
                   path('/login',views.login,name='login'),]

app02-urls:

app_name='app02'
urlpatterns=[path('',views.index,name='home'),
                   path('/login',views.login,name='login'),]

Call time:

reserve("app_name : url名")

This problem is solved.

Guess you like

Origin www.cnblogs.com/Zarax/p/11870654.html