在Django中使用AuthenticationForm [英] Using AuthenticationForm in Django

查看:180
本文介绍了在Django中使用AuthenticationForm的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用django使用AuthenticationForm表单,并发现我似乎无法获取表单进行验证。我把它放在一个简单的测试(假设是正确的)似乎不起作用。谁能在这里看到问题?

 >>>来自django.contrib.auth.forms import AuthenticationForm 
>>> POST = {'username':'test','password':'me',}
>>> form = AuthenticationForm(POST)
>>> form.is_valid()
False

有没有真正的原因它不会验证?我使用不正确吗?我已经基本建模了django自己的登录视图。

解决方案

尝试:

  form = AuthenticationForm(data = request.POST)


I'm attempting to use the AuthenticationForm form with django and finding out that I can't seem to get the form to validate. I widdled it down to a simple test(assuming it's correct) that doesn't seem to work. Can anyone see a problem here?

>>> from django.contrib.auth.forms import AuthenticationForm
>>> POST = { 'username': 'test', 'password': 'me', }
>>> form = AuthenticationForm(POST)
>>> form.is_valid()
False

Is there a real reason it won't validate? Am I using it incorrectly? I've basically modeled it after django's own login view.

解决方案

Try:

form = AuthenticationForm(data=request.POST)

这篇关于在Django中使用AuthenticationForm的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆