[Django]-How to add multiple attrs in Django forms

6👍

Have you tried this:

email = forms.EmailField(
    widget = forms.TextInput(attrs={'placeholder': 'Email', 'class': 'myClass', 'size': 'mySize'}))

This is normal Python syntax (inside the curly braces is a dict and a dict can have unlimited entries), and I don’t know, why it should not work.

Normally, when you have an API, where a dict is required, that is a clear sign, that multiple values are possible.

1👍

email = forms.EmailField(
widget = forms.TextInput(attrs={‘placeholder’: ‘Email’, ‘class’: ‘myClass’, ‘onkeyup’:’get code();’}))

Leave a comment