Задать вопрос

Тел: +7 965 3737 888

535

Просмотров

4

Ответов

newforms self-contained login form

<p>A simple login form that does the actual authentification itself.</p>
<p><strong>Usage:</strong></p>
if request.method == "POST":    
    loginform = LoginForm(request.POST)
    if loginform.login():            
        return HttpResponseRedirect(redir_url)
else:
    loginform = LoginForm()

Вопрос полезен? Да0/Нет0
file_4522.py(1.4Кб)
None

Ответы (4):

Ответsweecoo:03.08.2007
Ответ полезен? Да0/Нет0

Nice, although it does not clear the password if it is incorrect.

Ответnipul:30.05.2008
Ответ полезен? Да0/Нет0

The clean method should return self.cleaned_data

Ответmikehowarth:10.09.2007
Ответ полезен? Да0/Нет0

Struggling to get this snippet running.

Using Django 0.96 I'm getting the following errors:

Traceback:

Traceback (most recent call last): File "C:\Python25\lib\site-packages\django\core\handlers\base.py" in get_response 77. response = callback(request, callback_args, *callback_kwargs) File "D:\Web Dev\Test\eshop..\eshop\login\views.py" in login 10. if loginform.login(request): File "D:\Web Dev\Test\eshop..\eshop\login\forms.py" in login 56. login(request, self.user) File "C:\Python25\lib\site-packages\django\contrib\auth__init__.py" in login 53. request.session[BACKEND_SESSION_KEY] = user.backend

AttributeError at /login/ 'User' object has no attribute 'backend'

Ответrcoup:27.08.2007
Ответ полезен? Да0/Нет0

There is a minor typo in the example view:

if loginform.login():

should be

if loginform.login(request):