Skip to content

django-helpdesk/django-bootstrap5-form

Repository files navigation

Django bootstrap5 form

PyPI version

image

image

Twitter Bootstrap5 for Django Forms.

A simple Django template tag to work with Bootstrap 5

Forked from the original django-bootstrap-form by @tzangms.

Installation

Install django-bootstrap5-form with pip

$ pip install django-bootstrap5-form

Usage

Add "bootstrap5form" to your INSTALLED_APPS.

At the top of your template load in our template tags:

{% load bootstrap5form %}

Then to render your form:

<form role="form">
    <legend>Form Title</legend>
    {% csrf_token %}
    {{ form|bootstrap5form }}
    <div class="form-group">
      <button type="submit" class="btn btn-primary">Submit</button>
    </div>
</form>

You can also set class="form-vertical" on the form element.

To use class="form-inline" on the form element, also change the "bootstrap5form_inline".

It is also possible to create a horizontal form. The form class and template tag are both changed, and you will also need slightly different CSS around the submit button:

<form class="form-horizontal">
    <legend>Form Title</legend>
    {% csrf_token %}
    {{ form|bootstrap5form_horizontal }}
    <div class="form-group">
      <div class="col-sm-10 col-sm-offset-2">
        <button type="submit" class="btn btn-primary">Submit</button>
      </div>
    </div>
</form>