Back to Browse

How to Add HTML Classes to Django Form Fields

2.9K views
May 17, 2019
4:01

In this video, I'll cover how to add Bootstrap classes to Django form fields so your forms don't look horrific. There are a couple of ways to do it. The first way I talk about is by overriding __init__. The second way is by changing the attributes after the field has been created. The third and most common way is to just add a attrs dictionary to a widget. If all this sounds confusing, just check out the video. I don't take credit for any of this knowledge; I'm just trying to make this knowledge more digestible for people that get more out of watching videos. Helpful links: - https://stackoverflow.com/questions/401025/define-css-class-in-django-forms - https://docs.djangoproject.com/en/2.2/ref/forms/widgets/ - https://docs.djangoproject.com/en/2.2/ref/forms/widgets/#django.forms.TextInput

Download

0 formats

No download links available.

How to Add HTML Classes to Django Form Fields | NatokHD