I have 2 django app. user and management. I have added dashboard/ in main app urls which redirects to user app urls. For this we need to login. All urls in user app is: dashboard/ and for login dashboard/login but it shows error in /login.

ERROR:

Page not found (404) Request Method: POST Request URL: http://localhost:8000/login

Main app urls.py

from user import urls as user_urls
from django.contrib import admin
from django.urls import path, include

urlpatterns = [
    path('admin/', admin.site.urls),
    path('dashboard/', include(user_urls))
]+static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

User app urls.py

from django.urls import path, include
from nh_user import views as users_views
from management import urls as management_urls
urlpatterns = [
   path('login', users_views.user_login, name='user-login'),
   path('logout', users_views.user_logout, name='user-logout'),
   path('dashboard/', include(management_urls)),
   path('', users_views.index, name='user-index'),
]

1 Answers

0
robert lee On

You specified dashboard/ as the route for all the urls in your users app. Django won't look for these urls unless you include '/dashboard/' in your address bar.

Currently the working path is http://localhost:8000/dashboard/login.

If you want to change your login path to http://localhost:8000/login you need to remove 'dashboard/' as the route in your project urls.py.

from user import urls as user_urls
from django.contrib import admin
from django.urls import path, include

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include(user_urls))
]+static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

All the routes for the urls in your users app will now be at directly at http://localhost:8000/route-name without anything preceding them.