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.
CodePudding user response:
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'),
]