I am writing an simple django application and got stuck into this error, can some one please help me my views.py looks exactly as
Edit
There is your problem, in urls, you are pointing not to a view, but to a User
. Python is case sensitive, you know. :)
Your problem is instead of response
, middleware is getting a User
object, so somwhere, instead of response you are returning a user, I don't see it in your code though.
Regardless, why don't you use django's authentication views? They do same stuff as you are trying to implement.
from django.contrib.auth.views import login, logout
def custom_login(request):
if request.user.is_authenticated():
return HttpResponseRedirect('dashboards')
return login(request, 'login.html', authentication_form=LoginForm)
def custom_logout(request):
return logout(request, next_page='/')
Oh yeah, and add this to your settings:
LOGIN_REDIRECT_URL = '/dashboards/'
And here is a promised user
view:
from django.contrib.auth.decorators import login_required
@login_required
def user(request):
# btw 'user' variable is already available in templates
context = {'user': request.user}
return render_to_response('dashboards.html', context, context_instance=RequestContext(request))