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

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

问题描述

我试图在 django 中使用 AuthenticationForm 表单,但发现我似乎无法验证表单.我把它归结为一个似乎不起作用的简单测试(假设它是正确的).任何人都可以看到这里的问题吗?

<预><代码>>>>从 django.contrib.auth.forms 导入 AuthenticationForm>>>POST = {'用户名':'测试','密码':'我',}>>>表单 = AuthenticationForm(POST)>>>form.is_valid()错误的

是否存在无法验证的真正原因?我使用它不正确吗?我基本上是在 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天全站免登陆