Search code examples
djangodjango-formsdjango-registration

Django fields in django-registration


I am setting up django registration, and I came across this piece of code in the RegistrationForm --

attrs_dict = { 'class': 'required' }

email = forms.EmailField(widget=forms.TextInput
                        (attrs=dict(attrs_dict, maxlength=75)),
                        label='Email')

What does the part (attrs=dict(attrs_dict, maxlength=75)) mean/do? I know what the maxlength part does but was unclear what the creation of a dictionary is doing, and what the attrs_dict is doing. Any explanation of this piece of code would be great. Thank you.


Solution

  • A bit of test showed that dict(attr_dict, maxlenght=75) equals to

    {'class': 'required', 'maxlength':75}
    

    So when the email filed is rendered to an html element, 2 attributes, class and maxlength will be added to the label.