当前位置: 首页 > 面试题库 >

'WSGIRequest'对象没有属性'user'Django admin

沈弘文
2023-03-14
问题内容

当我尝试访问管理页面时,出现以下错误:

System check identified no issues (0 silenced).
June 21, 2016 - 15:26:14
Django version 1.9.7, using settings 'librato_chart_sender_web.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
Internal Server Error: /admin/
Traceback (most recent call last):
  File "/Library/Python/2.7/site-packages/django/core/handlers/base.py", line 149, in get_response
    response = self.process_exception_by_middleware(e, request)
  File "/Library/Python/2.7/site-packages/django/core/handlers/base.py", line 147, in get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/Library/Python/2.7/site-packages/django/contrib/admin/sites.py", line 265, in wrapper
    return self.admin_view(view, cacheable)(*args, **kwargs)
  File "/Library/Python/2.7/site-packages/django/utils/decorators.py", line 149, in _wrapped_view
    response = view_func(request, *args, **kwargs)
  File "/Library/Python/2.7/site-packages/django/views/decorators/cache.py", line 57, in _wrapped_view_func
    response = view_func(request, *args, **kwargs)
  File "/Library/Python/2.7/site-packages/django/contrib/admin/sites.py", line 233, in inner
    if not self.has_permission(request):
  File "/Library/Python/2.7/site-packages/django/contrib/admin/sites.py", line 173, in has_permission
    return request.user.is_active and request.user.is_staff
AttributeError: 'WSGIRequest' object has no attribute 'user'
[21/Jun/2016 15:26:18] "GET /admin/ HTTP/1.1" 500 78473

我是django的新手,但我遵循了本教程:https : //docs.djangoproject.com/en/1.9/ref/contrib/admin/

我没有任何自定义AdminSite和自定义AdminModel。

我已经用谷歌搜索了这个问题,但仍然无法以任何方式解决我的问题。你能帮我吗 ?

这是我的settings.py

"""
Django settings for librato_chart_sender_web project.

Generated by 'django-admin startproject' using Django 1.11.dev20160523235928.

For more information on this file, see
https://docs.djangoproject.com/en/dev/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/dev/ref/settings/
"""

import os

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/dev/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '*1@+=wzrqx^6$9z&@2@d8r(w$js+ktw45lv2skez(=kz+rwff_'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'librato_chart_sender',
    'fontawesome',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
]

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',
]

ROOT_URLCONF = 'librato_chart_sender_web.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'librato_chart_sender/templates')],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'librato_chart_sender_web.wsgi.application'


# Database
# https://docs.djangoproject.com/en/dev/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}


# Password validation
# https://docs.djangoproject.com/en/dev/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]


# Internationalization
# https://docs.djangoproject.com/en/dev/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'GMT'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/dev/howto/static-files/

STATIC_URL = '/static/'
STATICFILES_DIRS = [
    ('css', 'librato_chart_sender/static/css'),
    ('js', 'librato_chart_sender/static/js'),
    ('fonts', 'librato_chart_sender/static/fonts'),
]

和admin.py:

from django.contrib import admin
from .models import Configuration

# Register your models here.

admin.site.register(Configuration)

问题答案:

要解决此问题,请转到settings.py存在新样式的地方MIDDLEWARE(在Django 1.10中引入)

将其更改为旧样式 MIDDLEWARE_CLASSES



 类似资料:
  • 这是我得到的错误,我无法得到管理员登录屏幕。 属性错误在 /admin/ 'WSGIRequest' 对象没有属性 'user' 请求方法: GET 请求 URL: http://127.0.0.1:8000/admin/ Django 版本: 2.1.2 异常类型: 属性错误异常值: 'WSGIRequest' 对象没有属性 “用户” 异常位置: C:\用户\海王星\AppData\本地\程序\

  • 这是我的密码: 这条线给了我错误 "属性错误:'浮点'对象没有属性'exp'"。X,t是Numpy ndarray。

  • 问题内容: 我正在开发Django应用程序,并且出现以下错误 我的模型是这样构造的 我应该做什么? 问题答案: 首先,您必须非常小心地重写以具有非可选参数。记住,每次从一个查询集中获取一个对象时,它将被调用! 这是您想要的正确代码: 如果您只使用该对象的子类,我强烈建议在Animal上设置abstract选项。这样可以确保不为动物创建表,而仅为绵羊(等)创建表。如果未设置abstract,则将创建

  • 我创建了这个简单的GUI: 我让用户界面启动并运行。当我点击按钮时,我在控制台上得到以下错误: 为什么设置为?

  • 问题内容: 我将Selenium webdriver(chrome)与Python结合使用,试图从网页上的所有链接中获取 href 。当我尝试以下操作时: 它设法获取所有链接,但是在get_attribute上出现错误: “ WebElement”对象没有属性“ Get_Attribute” 尽管到处都看起来很正常。 问题答案: “ Get_Attribute”属性不存在,但是“ get_attr

  • 问题内容: 我创建了这个简单的GUI: 我启动并运行了UI。当我单击Grab按钮时,在控制台上出现以下错误: 为什么entryBox设置为None? 问题答案: 并且place在功能Entry对象和所有其他部件的回报None。在python中,执行此操作时.,表达式的结果为返回的值,因此。 你应该将其分成两行,如下所示: 这样,你就可以将参考存储在其中,并且可以按照你的期望进行布局。如果你以块的形