Django Widget Tweaks


1. Add a custom class to a widget:

from django import forms
from django_widget_tweaks.widgets import AttributeWidgetMixin

class CustomTextInput(AttributeWidgetMixin, forms.TextInput):
    attrs = {'class': 'my-custom-class'}

2. Add multiple custom classes to a widget:

from django import forms
from django_widget_tweaks.widgets import AttributeWidgetMixin

class CustomTextInput(AttributeWidgetMixin, forms.TextInput):
    attrs = {'class': 'my-custom-class1 my-custom-class2'}

3. Add a custom style to a widget:

from django import forms
from django_widget_tweaks.widgets import AttributeWidgetMixin

class CustomTextInput(AttributeWidgetMixin, forms.TextInput):
    attrs = {'style': 'color: red;'}

4. Add a custom placeholder to a widget:

5. Add a custom title to a widget:

6. Add a custom maxlength to a widget:

7. Add a custom pattern to a widget:

8. Add a custom autocomplete to a widget:

9. Add a custom autofocus to a widget:

10. Add a custom disabled to a widget:

11. Add a custom readonly to a widget:

12. Add a custom required to a widget:

13. Add a custom size to a widget:

14. Add a custom step to a widget:

15. Add a custom min to a widget:

16. Add a custom max to a widget:

17. Add a custom multiple to a widget:

18. Add a custom size to a widget:

19. Add a custom multiple to a widget:

20. Add a custom checked to a widget:

21. Add a custom value to a widget:

22. Add a custom checked to a widget:

23. Add a custom file type to a widget:

24. Add a custom accept to a widget:

25. Add a custom multiple to a widget:

26. Add a custom date type to a widget:

27. Add a custom time type to a widget:

28. Add a custom datetime type to a widget:

29. Add a custom datetime-local type to a widget:

30. Add a custom month type to a widget:

31. Add a custom week type to a widget:

32. Add a custom url type to a widget:

33. Add a custom email type to a widget:

34. Add a custom tel type to a widget:

35. Add a custom color type to a widget:

36. Add a custom search type to a widget: