I am trying to save a user id in a session using django.contrib.auth.login. But it does not work as expected.
I get an error login () takes exactly 1 argument (2)
With login (user) I get an AttributeError object at / login / User 'does not have the attribute' method '
I use a slightly modified example of the form http://docs.djangoproject.com/en/dev/topics/auth/ :
from django.shortcuts import render_to_response from django.contrib.auth import authenticate, login def login(request): msg = [] if request.method == 'POST': username = request.POST['u'] password = request.POST['p'] user = authenticate(username=username, password=password) if user is not None: if user.is_active: login(request, user) msg.append("login successful") else: msg.append("disabled account") else: msg.append("invalid login") return render_to_response('login.html', {'errors': msg})
there is nothing special about login.html:
<html> <head> <title></title> </head> <body> <form action="/login/" method="post"> Login: <input type="text" name="u"> <br/> Password: <input type="password" name="p"> <input type="submit" value="Login"> </form> {% if errors %} <ul> {% for error in errors %} <li>{{ error }}</li> {% endfor %} </ul> {% endif %} </body> </html>
Does anyone have an idea how to make login () work.
django
Alex Bolotov Jul 15 '09 at 22:28 2009-07-15 22:28
source share