‘WSGIRequest’ object has no attribute ‘username’
This is the error I get .
I have gone through most of the questions related to it and did some changes accordingly . But didn’t meet with the solution yet .
In my settings.py this is there
TEMPLATE_CONTEXT_PROCESSORS = ( "django.core.context_processors.debug", "django.core.context_processors.i18n")
TEMPLATE_CONTEXT_PROCESSORS += (
'django.core.context_processors.request',
'django.core.context_processors.debug',
'django.core.context_processors.i18n',
'django.core.context_processors.media',
'django.core.context_processors.static',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
)
AUTH_PROFILE_MODULE = "prof.userprofile"
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.middleware.doc.XViewMiddleware',
)
I want to know what does this error mean , as this is the first time I have come across such an error . And how to debug it ?
Edit:
Exception Value:
'WSGIRequest' object has no attribute 'username'
Exception Location: /home/satyajit/geodjango/geographic_admin/prof/views.py in view_foo, line 18
This is my views.py
from django.shortcuts import render_to_response
from django.contrib.gis.shortcuts import render_to_kml
from django import forms
from django.contrib.auth.models import User
from django.shortcuts import get_object_or_404, render_to_response
from django.http import HttpResponseRedirect, HttpResponse
from django.contrib.auth.decorators import login_required
@login_required
def view_foo(request):
user1 = User.objects.get(user=request.User.username)
return render_to_response('welcome.html', {})
Edit: ok I just realized how silly this query is and my mistake :D.
If you want the username, you could do something like this:
you get the user instance by
request.user.A little explanation: your initial query does not make much sense, because the User class does not have the field user. Also, this query is superfluous because the user instance is already provided by the request (request.user, which is the user whose session