How to Apply Bootstrap CSS to a Django Form (Django Tutorial) | Part 50



https://i.ytimg.com/vi/_oMY2o2NhWM/hqdefault.jpg



Enjoyed my video? Leave a like!
GitHub Link: https://github.com/maxg203
Personal Website: http://maxgoodridge.com

Original source


5 responses to “How to Apply Bootstrap CSS to a Django Form (Django Tutorial) | Part 50”

  1. There is an easier way I think.. instead of templating the form into html via {{ form.as_p }} or any other way .. you'd do this ..

    {% for el in forms %}

    <label class="Whateverclass">{{ el.label_tag }}</label>

    <div class="whateverdiv">

    {{ el }}

    </div>

    el.label_tag is the label of the forms like.. "post".. and just el is the actual input etc.

    {% endfor %}

  2. There is even easier way to add class to django widgets: if you are using virtualenv just add class="form-control" to your django files:
    env/lib/python3.5/site-packages/django/forms/templates/django/forms/widgets/input.html
    env/lib/python3.5/site-packages/django/forms/templates/django/forms/widgets/textarea.html
    Then each form field rendered with TextInput() widget will have class="form-control" ๐Ÿ™‚ And you don't have to add attr everytime you are creating a form field ๐Ÿ™‚

Leave a Reply