Olá pessoal, após criar a autenticação do usuário no Django, estou tendo o seguinte erro ao carregar a aplicação.
AttributeError at /
'WSGIRequest' object has no attribute 'user'
o meu código está assim:
settings.py
"""
Django settings for connectedin project.
Generated by 'django-admin startproject' using Django 1.9.1.
For more information on this file, see
https://docs.djangoproject.com/en/1.9/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.9/ref/settings/
"""
import os
import posixpath
# 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.9/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'f232c730-643c-4c4e-b22b-6ab5cc735838'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
'app',
# Add your apps here to enable them
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'perfis',
'usuarios'
]
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.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'connectedin.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'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 = 'connectedin.wsgi.application'
#código omitido
STATIC_URL = '/static/'
LOGIN_URL='/login/'
LOGOUT_URL='/logout/'
LOGIN_REDIRECT_URL='/'
#código omitido
views.py
from django.shortcuts import render, redirect
from django.http import HttpResponse
from perfis.models import Perfil, Convite
from django.contrib.auth.decorators import login_required
@login_required
def index(request):
return render(request, 'index.html', { 'perfis' : Perfil.objects.all(),
'perfil_logado' : get_perfil_logado(request)})
@login_required
def perfis(request, perfil_id):
perfil = Perfil.objects.get(id=perfil_id)
perfil_logado = get_perfil_logado(request)
ja_eh_contato = perfil in perfil_logado.contatos.all()
return render(request, 'perfil.html', {'perfil' : perfil, 'perfil_logado' : get_perfil_logado(request),
'ja_eh_contato' : ja_eh_contato})
@login_required
def convidar(request, perfil_id):
perfil_a_convidar = Perfil.objects.get(id=perfil_id)
perfil_logado = get_perfil_logado(request)
perfil_logado.convidar(perfil_a_convidar)
return redirect('index')
@login_required
def aceitar(request, convite_id):
convite = Convite.objects.get(id=convite_id)
convite.aceitar()
return redirect('index')
@login_required
def get_perfil_logado(request):
return request.user.perfil
urls.py
from django.conf.urls import url
from usuarios.views import RegistrarUsuarioView
from django.contrib.auth import views as auth_views
import app.forms
import app.views
urlpatterns = [
# Examples:
url(r'^registrar/$', RegistrarUsuarioView.as_view(), name='registrar'),
url(r'^login/$', auth_views.login, { 'template_name':'login.html' }, name='login'),
url(r'^logout/$', auth_views.logout_then_login, {'login_url':'/login/'}, name='logout')
]
Já tentei pesquisar em algum fórum, alguma resolução, mas nada ainda, tentei realizar a alteração do nome do módulo de MIDDLEWARE_CLASSES, para MIDDLEWARE, e obtenho um outro erro,
django.core.exceptions.ImproperlyConfigured: WSGI application 'connectedin.wsgi. application' could not be loaded; Error importing module.
Se possível uma luz, pois não estou conseguindo resolver.