Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

django url from a django app is giving 404 error

demo > url.py (This is main django project url file)

from django.contrib import admin
from django.urls import path, include
from . import views

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', views.home, name='home'),
    path('about', views.about, name='about'),
    path('contact', views.contact, name='contact'),    
    path(r'^user/', include('user.urls')), 
]

user > url.py (this is a user app inside django project’s url file)

from django.urls import path
from . import views

urlpatterns = [
    path(r'^/login', views.login, name='login'),
]

now i am trying to open http://127.0.0.1:8000/user/login but its giving me 404 error.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You don’t use a regex for path(…) [Django-doc], for regexes, you use re_path(…) [Django-doc]. But here it is not necessary: you can define this with path(…):

from django.contrib import admin
from django.urls import path, include
from . import views

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', views.home, name='home'),
    path('about', views.about, name='about'),
    path('contact', views.contact, name='contact'),
    path('user/', include('user.urls')),
]

and for user/urls.py:

urlpatterns = [
    path('login/', views.login, name='login'),
]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading