简体   繁体   English

当前路径admin与任何这些都不匹配。 詹戈

[英]The current path, admin, didn't match any of these. django

I use django 2.0 my urls.py file: 我使用django 2.0我的urls.py文件:

"""django_direct URL Configuration

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

urlpatterns = [
    url('^admin/', admin.site.urls),
    # url(r'^/', include('main_app.urls')),
    url('/', views.index),
]

This is url, I visit: https://django-direct-jonsdirewolf.c9users.io/admin I use cloud 9 Ide (it's online ide) so it's like localhost:8000/admin 这是URL,我访问: https : //django-direct-jonsdirewolf.c9users.io/admin我使用cloud 9 ide(它是在线ide),所以就像localhost:8000 / admin 在此处输入图片说明

Internal Server Error: /admin/
Traceback (most recent call last):
  File "/usr/local/lib/python3.4/dist-packages/django/core/handlers/exception.py", line 35, in inner
    response = get_response(request)
  File "/usr/local/lib/python3.4/dist-packages/django/core/handlers/base.py", line 128, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "/usr/local/lib/python3.4/dist-packages/django/core/handlers/base.py", line 126, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/usr/local/lib/python3.4/dist-packages/django/contrib/admin/sites.py", line 241, in wrapper
    return self.admin_view(view, cacheable)(*args, **kwargs)
  File "/usr/local/lib/python3.4/dist-packages/django/utils/decorators.py", line 142, in _wrapped_view
    response = view_func(request, *args, **kwargs)
  File "/usr/local/lib/python3.4/dist-packages/django/views/decorators/cache.py", line 44, in _wrapped_view_func
    response = view_func(request, *args, **kwargs)
  File "/usr/local/lib/python3.4/dist-packages/django/contrib/admin/sites.py", line 212, in inner
    if not self.has_permission(request):
  File "/usr/local/lib/python3.4/dist-packages/django/contrib/admin/sites.py", line 186, in has_permission
    return request.user.is_active and request.user.is_staff
AttributeError: 'WSGIRequest' object has no attribute 'user'
[18/Apr/2018 20:38:23] "GET /admin/ HTTP/1.1" 500 86326
Not Found: /admin
[18/Apr/2018 20:38:34] "GET /admin HTTP/1.1" 404 2087
Internal

尝试将您的网址定义更改为此:

url(r'^admin/', admin.site.urls),

This helped: 这有助于:

In case anyone is having this problem with Django 2.0, the following configuration with new-style MIDDLEWARE seems to work (docs here): 如果有人在Django 2.0上遇到此问题,则使用新型MIDDLEWARE的以下配置似乎可以正常工作(此处的文档):

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

thanks guys from here: https://stackoverflow.com/a/47795057/2950593 谢谢来自这里的人: https : //stackoverflow.com/a/47795057/2950593

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Python/Django“找不到页面”错误:“当前路径,...,与这些都不匹配。” - Python/Django "page not found" error: "The current path, ... , didn’t match any of these." 空路径与其中任何一个都不匹配。 Django - The empty path didn’t match any of these. Django 当前路径 search_shop/5ka/ 与其中任何一个都不匹配。 Django - The current path, search_shop/5ka/, didn't match any of these. Django 当前路径,客户,与这些都不匹配。 即使所有其他路径都正确运行 - The current path, customer, didn't match any of these. even when all other path runs correctly 错误“当前路径user_info /与任何这些都不匹配。” - error “The current path, user_info/, didn't match any of these.” django-当前路径…与这些都不匹配 - django - The current path … didn't match any of these django 当前路径,不匹配任何这些 - django The current path,didn't match any of these (“Django 尝试了这些 URL 模式......空路径与其中任何一个都不匹配。”)如何修复“找不到页面(404)”错误 - ("Django tried these URL patterns... The empty path didn't match any of these.") How to fix "Page not found (404)" error 如何修复“找不到页面(404)”错误(“Django 尝试了这些 URL 模式......空路径与其中任何一个都不匹配。”) - How to fix "Page not found (404)" error ("Django tried these URL patterns... The empty path didn't match any of these.") 在 /about/ 找不到页面。 当前路径 about/ 与其中任何一个都不匹配。 为什么django不能走我的URL路径? - Page not found at /about/. The current path, about/, did not match any of these. Why can't django follow my URL path?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM