Home > Back-end >  Page not found at/admin
Page not found at/admin

Time:02-28

I'm a very beginner. When I tried to go visit this (http://127.0.0.1:8000/admin), I couldn't. Here have shown page not found. What can be the solution?

Problem that I faced:

Page not found (404)
“D:\1_WebDevelopment\Business_Website\admin” does not exist
Request Method: GET
Request URL:    http://127.0.0.1:8000/admin
Raised by:  django.views.static.serve
Using the URLconf defined in business_website.urls, Django tried these URL patterns, in this order:

admin/
admin/
[name='index']
singup [name='handle_singUp']
login [name='handle_login']
logout [name='handle_logout']
contact [name='handle_contact']
frontend_orders [name='frontend_orders']
hire_me [name='hire_me']
^(?P<path>.*)$
The current path, admin, matched the last one.

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.

Problem : open the picture

business_website urls.py:

from django.contrib import admin
from django.urls import path,include
from django.conf import settings
from django.conf.urls.static import static

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include('business_app.urls')),

]  static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

business_website url.py : open the picture

business_app urls.py:

from os import name
from django.contrib import admin
from django.urls import path
from .import views

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', views.index, name="index"),
    path('singup', views.handle_singUp, name= "handle_singUp"),
    path('login', views.handle_login, name="handle_login"),
    path('logout', views.handle_logout, name="handle_logout"),
    path('contact', views.handle_contact, name="handle_contact"),
    path('frontend_orders', views.frontend_orders, name="frontend_orders"),
    path('hire_me', views.hire_me, name="hire_me")

]

business_app url.py : open the picture

CodePudding user response:

Delete from business_app urls.py this row:

path('admin/', admin.site.urls),

You should not call it twice.

You should set MEDIA_URL in settings to something. Like:

MEDIA_URL = '/media/'

CodePudding user response:

Django urls need to have a trailing slash and the url you tried to access does not have it, check in your settings.py file if APPEND_SLASH is set to false

Among Django's many built-in features is APPEND_SLASH, which by default is set to True and automatically appends a slash / to URLs that would otherwise 404.

You can turn off this option by just setting APPEND_SLASH = False

You can read more here about why django uses trailing slashes

CodePudding user response:

You have the same admin path defined in your root urls.py and in your app. It should probably be in just the root. Remove it from:

from os import name
from django.contrib import admin
from django.urls import path
from .import views

urlpatterns = [
    # path('admin/', admin.site.urls), ##### REMOVE
    path('', views.index, name="index"),
    path('singup', views.handle_singUp, name= "handle_singUp"),
    path('login', views.handle_login, name="handle_login"),
    path('logout', views.handle_logout, name="handle_logout"),
    path('contact', views.handle_contact, name="handle_contact"),
    path('frontend_orders', views.frontend_orders, name="frontend_orders"),
    path('hire_me', views.hire_me, name="hire_me")
]

Edit
After trying, and failing to reproduce the OP's error on my machine using all the answers given as of this writing, it turned out my original answer was not correct (not incorrect, but also not the solution), in fact the original answer given by Jaime Ortiz, was most likely the correct one.

But why was it so hard to come to this realization? Within the link he provided was this, which is why, when I initially tried his solution it did not work. Below is from the answer provided by All Іѕ Vаиітy in that link. Note that within the [] is my insertion.

Since django observes both the urls [the one with the trailing slash and the one without] as different, if you are caching your app, Django will keep two copies for same page at ...

So either use admin/ instead of admin, or apply APPEND_SLASH = False to your settings.py, clear your browser cache and then you can use either, Django will append the slash automatically.

  • Related