Reputation: 229
I have two apps in my django project one is "home" and other is "administrator". I am using home app for frontend of the site and administrator app for admin panel and the urls' for accessing both frontend and admin panel respectively are :-
www.domainname.com/home
www.domainname.com/administrator
main urls.py file is :-
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'))
]
Home's urls.py file is :-
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')
]
Admin's urls.py file is :-
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')
]
As you can check that there are some common url's in both app's file, like index, dashboard, logout help.
These urls are creating problem if i link them in href, for example if i link "help" url in frontend using
<a href="{% url 'help' %}" >
It tries to redirect me to admin panel's help url, and if i change the order of apps in main urls.py file than vice versa problem occurs.
Upvotes: 2
Views: 756
Reputation: 968
You can try adding a namespace to your urls
urlpatterns = [
url(r'^home/', include('home.urls', namespace='home')),
url(r'^administrator/', include('administrator.urls', namespace='admin'))
]
Then you can access them like:
<a href="{% url 'home:help' %}" >
<a href="{% url 'admin:help' %}" >
Upvotes: 1