如何在django urls中直接调用admin

How to directly call admin in django urls

在我的 python 中,我有 url 个像 :

urlpatterns = [
    path('admin/', admin_site.urls),
    url(r'^ckeditor/', include('ckeditor_uploader.urls')),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

当我有 url 时:http://localhost:8000/ 我得到的屏幕像

但是当我使用 http://localhost:8000/admin 时我可以使用我的管理员登录 pannel.what 我真正想要的是当我使用 http://localhost:8000/ 它直接调用http://localhost:8000/admin 。任何人都可以帮我解决这个问题吗??

只需从 url 中删除 admin 一词,如下所示:

path('', admin_site.urls),

这意味着您的管理页面将成为您的主页。

或者,您可以进行重定向:

from django.views.generic.base import RedirectView
from django.urls import re_path
re_path(r'^$', RedirectView.as_view(url='/admin'))