我的django项目中有两个应用程序,一个是" home"和其他人是#34;管理员"。我正在使用家庭应用程序作为网站的前端和管理员应用程序管理面板和网址'分别访问前端和管理面板的是: -
www.domainname.com/home
www.domainname.com/administrator
主要urls.py文件是: -
from django.conf.urls import include, url
from django.contrib import admin
urlpatterns = [
url(r'^home/', include('home.urls')),
url(r'^administrator/', include('administrator.urls'))
]
主页的urls.py文件是: -
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^$', views.index, name='index'),
url(r'^sport$', views.sport, name='sport'),
url(r'^register$', views.signup_signin, name='register'),
url(r'^login$', views.login, name='login'),
url(r'^signup$', views.signup, name='signup'),
url(r'^registered-successfully$', views.registered_successfully, name='registered-successfully'),
url(r'^logout$', views.logout_view, name='logout'),
url(r'^dashboard$', views.dashboard, name='dashboard'),
url(r'^create-new-event$', views.create_new_event, name='create-new-event'),
url(r'^help$', views.help, name='help'),
url(r'^account-settings$', views.account_settings, name='account-settings')
]
管理员的urls.py文件为: -
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^$', views.index, name='index'),
url(r'^logout$', views.logout, name='logout'),
url(r'^dashboard$', views.dashboard, name='dashboard'),
url(r'^profile$', views.profile, name='profile'),
url(r'^edit-profile$', views.edit_profile, name='edit-profile'),
url(r'^check-password$', views.check_password, name='check-password'),
url(r'^help$', views.faq_management, name='help')
]
您可以检查应用程序文件中是否存在某些常用网址,例如索引,信息中心,注销帮助。
如果我在href中链接它们,这些网址会产生问题,例如,如果我链接" help"使用
的前端网址<a href="{% url 'help' %}" >
它尝试将我重定向到管理面板的帮助网址,如果我更改主urls.py文件中的应用顺序,则反之亦然。
答案 0 :(得分:1)
您可以尝试在网址中添加命名空间
urlpatterns = [
url(r'^home/', include('home.urls', namespace='home')),
url(r'^administrator/', include('administrator.urls', namespace='admin'))
]
然后您可以访问它们,如:
<a href="{% url 'home:help' %}" >
<a href="{% url 'admin:help' %}" >