Admin page couldn't get found

时间:2018-12-03 13:00:33

标签: python django

Here come my urls.py page code:

from django.contrib import admin  
from django.urls import path 

admin.autodiscover()

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

When I run Django I get 404 error:

Page not found (404) Request Method: GET Request URL: http://localhost:51169/admin Using the URLconf defined in DjangoWebProject3.urls, Django tried these URL patterns, in this order:

admin/ The current path, admin, didn't match any of these.

I know this is a famous problem but couldn't find any answer for it.

What is wrong?

2 个答案:

答案 0 :(得分:1)

The admin url is http://localhost:51169/admin/. You are missing the trailing slash.

Normally, Django should redirect from /admin to /admin/. If it hasn't it suggests that you've changed something in the settings, or you've upgraded Django from an older version without switching from MIDDLEWARE_CLASSES to MIDDLEWARE in your settings.py.

答案 1 :(得分:0)

正如Alasdair所说,我更新了Django,但之前没有更新设置: 知道: 在设置中,我将middleware_classes更改为中间件,并注释了其中一种中间件:#'django.contrib.auth.middleware.SessionAuthenticationMiddleware'

现在登录页面有效!

谢谢