I'm trying to use django-crispy-forms to display the built-in AuthenticationForm with the login view in django. I'm having issues subclassing AuthenticationForm - I'm getting an AttributeError. The error says 'WSGIrequest' object has no attribute 'get'. Here is my form:
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)
I think this error has to do with the login view being called via get from a redirect (I'm using the @login_required decorator). Does anyone have any ideas on how to subclass built in forms with django-crispy-forms and avoid this error?
It looks like you've got an error in your form:
class LoginForm(AuthenticationForm):
def __init__(self, *args, **kwargs):
super(LoginForm, self).__init__(*args, **kwargs)
self.helper = FormHelper()
self.helper.form_tag = False
self.helper.layout = Layout(
Field('username', placeholder="username"),
Field('password', placeholder="password"),
)
You are calling super, passing parent class AuthenticationForm not LoginForm.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With