Django 1.7 AttributeError:' WSGIRequest'对象没有属性'用户'

时间:2016-11-16 20:52:06

标签: python django apache2

我已经阅读了一些类似的帖子,但没有人帮助我,我建议创建一个新问题。

我尝试访问继承的网站的管理页面,我为此创建了一个用户,但是我到达了管理页面,我得到了下面的堆栈跟踪。我还添加了settings.py以防万一。

任何输入都非常感激。

中号

settings.py

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/1.10/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'XXXXX'

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

# ALLOWED_HOSTS = ['0.0.0.0', 'localhost']
ALLOWED_HOSTS = ['192.168.1.36',  'localhost']


# Application definition

INSTALLED_APPS = [

    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    # 'south',
    'CordeliaHanelBackend',
    'tastypie',
    'StudioHanel',
]

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 = 'CordeliaHanelBackend.urls'

PROJECT_ROOT = os.path.dirname(os.path.dirname(__file__))
TEMPLATE_DIRS = (
    '/var/www/CordeliaHanelBackend-master/StudioHanel/templates2',
)

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        # 'DIRS': ['/var/www/CordeliaHanelBackend-master/StudioHanel/templates2'],
        '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 = 'CordeliaHanelBackend.wsgi.application'


# Database
# https://docs.djangoproject.com/en/1.10/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/1.10/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/1.10/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


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

STATIC_URL = '/static/'

STATICFILES_DIRS = (
    # os.path.join(BASE_DIR, "static"),
    # '/var/www/CordeliaHanelBackend-master/StudioHanel/templates2',
    '/var/www/CordeliaHanelFrontend-master/www/dist/',
        # '/var/www/CordeliaHanelFrontend-master/www/app',
        # '/var/www/CordeliaHanelBackend-master/StudioHanel/static',
    )

# STATIC_ROOT = '/var/www/CordeliaHanelFrontend-master/www/app'


STATICFILES_FINDERS = [
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
]

# DEFAULT_FILE_STORAGE = '/var/www/CordeliaHanelFrontend-master/www/app'


SOUTH_DATABASE_ADAPTER = {
'default': 'south.db.sqlite3'
}

堆栈跟踪/错误日志

[Wed Nov 16 20:50:07.826886 2016] [wsgi:error] [pid 30866:tid 139796884670208] [remote 127.0.0.1:59644] Internal Server Error: /admin/
[Wed Nov 16 20:50:07.826923 2016] [wsgi:error] [pid 30866:tid 139796884670208] [remote 127.0.0.1:59644] Traceback (most recent call last):
[Wed Nov 16 20:50:07.826927 2016] [wsgi:error] [pid 30866:tid 139796884670208] [remote 127.0.0.1:59644]   File "/var/www/CordeliaHanelBackend-master/env/lib/python2.7/site-packages/django/core/handlers/base.py", line 111, in get_response
[Wed Nov 16 20:50:07.826930 2016] [wsgi:error] [pid 30866:tid 139796884670208] [remote 127.0.0.1:59644]     response = wrapped_callback(request, *callback_args, **callback_kwargs)
[Wed Nov 16 20:50:07.826932 2016] [wsgi:error] [pid 30866:tid 139796884670208] [remote 127.0.0.1:59644]   File "/var/www/CordeliaHanelBackend-master/env/lib/python2.7/site-packages/django/contrib/admin/sites.py", line 225, in wrapper
[Wed Nov 16 20:50:07.826934 2016] [wsgi:error] [pid 30866:tid 139796884670208] [remote 127.0.0.1:59644]     return self.admin_view(view, cacheable)(*args, **kwargs)
[Wed Nov 16 20:50:07.826937 2016] [wsgi:error] [pid 30866:tid 139796884670208] [remote 127.0.0.1:59644]   File "/var/www/CordeliaHanelBackend-master/env/lib/python2.7/site-packages/django/utils/decorators.py", line 105, in _wrapped_view
[Wed Nov 16 20:50:07.826939 2016] [wsgi:error] [pid 30866:tid 139796884670208] [remote 127.0.0.1:59644]     response = view_func(request, *args, **kwargs)
[Wed Nov 16 20:50:07.826941 2016] [wsgi:error] [pid 30866:tid 139796884670208] [remote 127.0.0.1:59644]   File "/var/www/CordeliaHanelBackend-master/env/lib/python2.7/site-packages/django/views/decorators/cache.py", line 52, in _wrapped_view_func
[Wed Nov 16 20:50:07.826944 2016] [wsgi:error] [pid 30866:tid 139796884670208] [remote 127.0.0.1:59644]     response = view_func(request, *args, **kwargs)
[Wed Nov 16 20:50:07.826946 2016] [wsgi:error] [pid 30866:tid 139796884670208] [remote 127.0.0.1:59644]   File "/var/www/CordeliaHanelBackend-master/env/lib/python2.7/site-packages/django/contrib/admin/sites.py", line 193, in inner
[Wed Nov 16 20:50:07.826948 2016] [wsgi:error] [pid 30866:tid 139796884670208] [remote 127.0.0.1:59644]     if not self.has_permission(request):
[Wed Nov 16 20:50:07.826951 2016] [wsgi:error] [pid 30866:tid 139796884670208] [remote 127.0.0.1:59644]   File "/var/www/CordeliaHanelBackend-master/env/lib/python2.7/site-packages/django/contrib/admin/sites.py", line 150, in has_permission
[Wed Nov 16 20:50:07.826953 2016] [wsgi:error] [pid 30866:tid 139796884670208] [remote 127.0.0.1:59644]     return request.user.is_active and request.user.is_staff
[Wed Nov 16 20:50:07.826955 2016] [wsgi:error] [pid 30866:tid 139796884670208] [remote 127.0.0.1:59644] AttributeError: 'WSGIRequest' object has no attribute 'user'

WSGI文件

import os

master/env/lib/python2.7/site-packages/')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "CordeliaHanelBackend.settings")

from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

1 个答案:

答案 0 :(得分:1)

我遇到了同样的问题,我修复了:

1)将MIDDLEWARE更改为MIDDLEWARE_CLASSES 2)评论出SecurityMiddleware

如下所示:

MIDDLEWARE_CLASSES = [
    # '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',
]