加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

python – 使用内置AuthenticationForm时的Django-crispy-forms

发布时间:2020-12-20 11:26:31 所属栏目:Python 来源:网络整理
导读:我正在尝试使用 django-crispy-forms在django中显示带有登录视图的内置AuthenticationForm.我有问题继承AuthenticationForm – 我得到一个AttributeError.错误说’WSGIrequest’对象没有属性’get’.这是我的表格: class LoginForm(AuthenticationForm): de
我正在尝试使用 django-crispy-forms在django中显示带有登录视图的内置AuthenticationForm.我有问题继承AuthenticationForm – 我得到一个AttributeError.错误说’WSGIrequest’对象没有属性’get’.这是我的表格:

class LoginForm(AuthenticationForm):
    def __init__(self,*args,**kwargs):
        self.helper = FormHelper()
        self.helper.form_tag = False
        self.helper.layout = Layout(
            Field('username',placeholder="username"),Field('password',placeholder="password"),)
        super(AuthenticationForm,self).__init__(*args,**kwargs)

我认为这个错误与通过重定向获取的登录视图有关(我正在使用@login_required装饰器).有没有人对如何使用django-crispy-forms子类化内置表单有任何想法,并避免此错误?

解决方法

看起来您的表单中有错误:

class LoginForm(AuthenticationForm):
    def __init__(self,**kwargs):
        super(LoginForm,**kwargs)
        self.helper = FormHelper()
        self.helper.form_tag = False
        self.helper.layout = Layout(
            Field('username',)

你正在调用super,传递父类AuthenticationForm而不是LoginForm.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读