My Django project settings seem to form an error
Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8000/Billing/
Using the URLconf defined in eCommerce.urls, Django tried these URL patterns, in this order:
admin/
The current path, Billing/, didn’t match any of these.
You’re seeing this error because you have DEBUG = True in your Django settings file. Change that to False, and Django will display a standard 404 page.
This is shown when I tried to create an app using django Here is the code for the program
main.urls
from django.contrib import admin
from django.urls import path, include
from BillingST.eCommerce.Billing import views
urlpatterns = [
path("admin/", admin.site.urls),
path("Billing/", include('Billing.urls')),
path('', views.access, name='access')
]
billing.urls
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('Billing/', include('Billing.urls')),
path('admin/', admin.site.urls),
]
I was trying to run the code for billing page, but it says to navigate to admin
Your billing.urls
essentially make it impossible to visit a view, since it keeps recursively including.
Indeed, first there is the main.urls
, which looks like:
path('Billing/', include('Billing.urls'))
so that means it will only go to Billing.urls
if the path starts with Billing/
, which it does.
But then we see:
path('Billing/', include('Billing.urls'))
in the billing.urls
, so if there is a second Billing/
in the path, it will descend to the next level, but even if that is the case, it will keep looking for more Billing/
s.
Rewrite the billing.urls
to:
# billing/urls.py
from BillingST.eCommerce.Billing import views
from django.contrib import admin
from django.urls import include, path
urlpatterns = [
path('', views.access),
path('admin/', admin.site.urls),
]
and remove the view from the main.urls
:
# main/urls.py
from django.contrib import admin
from django.urls import include, path
# from BillingST.eCommerce.Billing import views
urlpatterns = [
path('admin/', admin.site.urls),
path('Billing/', include('Billing.urls')),
# path('', views.access, name='access')
]
Note: Python modules are normally written in snake_case, not PascalCase, so it should be
billing
, not.Billing
The issue is how your URL patterns are structured and included.
main.urls - You include Billing.urls
with the path "Billing/". This means Django will look for patterns in Billing.urls
prefixed by "Billing/."
billing.urls - Inside Billing.urls
, you're including Billing.urls
again (recursive inclusion). This causes a loop and breaks the URLs. Billing.urls
doesn't define any valid endpoint, so you get a 404.
Define the correct URL structure for Billing
main.urls -
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path("admin/", admin.site.urls),
path("Billing/", include('Billing.urls')), # Include Billing app URLs
]
billing.urls -
- Do not include
Billing.urls
within itself.
from django.urls import path
from . import views # Import the views for the Billing app
urlpatterns = [
path("", views.billing_home),
path("details/", views.billing_details),
]