Django Admin Page not found (404) - First time accessing. error with only admin page

TL;DR: Having trouble accessing 0.0.0.0/8000/admin but with other pages (e.g. http://127.0.0.1:8000/about/) everything is OK.

I'm creating a Django project, but I'm not reaching admin page. Other pages are OK.

Error:

Page not found (404)

Request Method:GET Request URL:http://127.0.0.1:8000/admin

Using the URLconf defined in ProjetoDjango131026.urls, Django tried these URL patterns, in this order:

  1. [name='index']

  2. contact/ [name='contact']

  3. about/ [name='contact']

The current path, admin, 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.

urls.py:

"""
URL configuration for ProjetoDjango131026 project.

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/5.2/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  path('', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.urls import include, path
    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path, include

from django.conf import settings

from ProjetoDjango131026.views import index, contact, about  # added in lesson 25

""" urlpatterns = [
    path('admin/', admin.site.urls),
    path('', index, name='index'), # added in lesson 25
    path('contact/', contact, name='contact'), # added in lesson 25
    path('about/', about, name='contact'), # added in lesson 25
] # added in lesson 25 """

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include('ProjetoDjango131026.urls')), #altered in lesson 25
    path('contact/', include('ProjetoDjango131026.urls')), # added in lesson 25
    path('about/', include('ProjetoDjango131026.urls')), # added in lesson 25
]

App urls.py:

from django.urls import path # File created in lesson 25

from ProjetoDjango131026.views import index, contact, about, admin # added in lesson 25

urlpatterns = [
    path('', index, name='index'),  # added in lesson 25
    path('contact/', contact, name='contact'),  # added in lesson 25
    path('about/', about, name='contact'),  # added in lesson 25
]
Вернуться на верх