Best way to use Bootstrap with Django

After some research, I have a choice between two ways to integrate Bootstrap into Django.

The first requires some changes in your templates, the second requires changes in your views.

Example for 1.)

* [...] {{form | as_bootstrap}} [...] *

{% load bootstrap_toolkit %} <form action="/url/to/submit/" method="post"> {% csrf_token %} {{ form|as_bootstrap }} <div class="actions"> <button type="submit" class="btn primary">Submit</button> </div> </form> 

Example for 2.)

[...] class LoginForm (BootstrapForm) [...]

 from bootstrap.forms import BootstrapForm, Fieldset class LoginForm(BootstrapForm): class Meta: layout = ( Fieldset("Please Login", "username", "password", ), ) username = forms.CharField(max_length=100) password = forms.CharField(widget=forms.PasswordInput(), max_length=100) 

Which method is recommended? Or any other method?

+4
source share
1 answer

If it's just about forms, you might want to take a look at django-crispy-forms too. This is the successor to django-uni-form and supports bootstrap forms.

https://github.com/maraujop/django-crispy-forms

+11
source

Source: https://habr.com/ru/post/1434214/


All Articles