I want to override the default forms of django-allauth in order to change\add default widget attributes, class variables without changing the initial code of allauth form. How can I do that?
My workspace:
1) installed django-allauth, as a package through pip;
2) configured settings, according to the recommendations of the project on github;
3) locally created templates signin, signup;
4) created forms.py, which defines a child class forms django-allauth
from allauth.account import SigninForm class mySigninForm (SigninForm): username = ...//override variable
Is this right way?
Thanks!
If you'd like to use the methods or functionalities provided by the allauth forms then overriding the form classes like you currently are is your best bet.
from allauth.account.forms import LoginForm
from django import forms
from myapp.forms import widgets
class MyLoginForm(LoginForm):
// Override attributes
existing_field = forms.CharField(widget=widgets.CustomWidget())
// Add Custom Attributes
new_field = forms.CharField(widget=widgets.CustomWidget())
If you want a completely custom form, you can use a custom django form and then use it in the view. For Example:
from django import forms
from myapp.forms import widgets
class MyLoginForm(forms.Form):
// Add atributes and methods
some_field = forms.CharField(widget=widgets.CustomWidget())
from django.views.generic.edit import FormView
from myapp.forms import MyLoginForm
LoginUser(FormView):
form = MyLoginForm
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