Reputation: 373
I have a very simple Django installation with one app, but I cannot get the urls.py
configured correctly. It's strange, because I have the same config in another application, which works perfectly.
urls.py
:
from django.contrib import admin
from django.urls import include, path
urlpatterns = [
path('subscribe/', include('newsletter.urls')),
path('subscription-confirmation/<str:key>/', include('newsletter.urls')),
path('admin/', admin.site.urls),
]
APP urls.py
from django.urls import path
from newsletter.views import subscribe, subscription_conf
urlpatterns = [
path('subscribe/', subscribe),
path('subscription-confirmation/<str:key>/', subscription_conf),
]
Error in browser:
Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8000/subscribe/
Using the URLconf defined in backoffice.urls, Django tried these URL patterns, in this order:
1. subscribe/ subscribe/
2. subscribe/ subscription-confirmation/<str:key>/
3. subscription-confirmation/<str:key>/
4. admin/
The current path, subscribe/, didn’t match any of these.
I'm pulling my hair out with this, what am I doing wrong?
Upvotes: 1
Views: 79
Reputation: 547
Actually the page is really not found. At least nothing points to the URL which you called.
You requested: http://127.0.0.1:8000/subscribe/
Which is looking for: subscribe/
But you do not have that, since you also included the app's url in that line. So you only have http://127.0.0.1:8000/subscribe/subscribe
I think you should:
urls.py
:urlpatterns = [
path('', include('newsletter.urls')),
path('admin/', admin.site.urls),
]
urls.py
:urlpatterns = [
path('subscribe/', subscribe),
path('subscription-confirmation/<str:key>/', subscription_conf),
]
Upvotes: 1