After some research I have the choice between two ways of integrating Bootstrap into Django.
The first one requires some changes in your templates, the second one 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 way is recommended? Or any other method?
If it's just about the forms, maybe you want to have a look at django-crispy-forms, too. It's the successor of django-uni-form and supports bootstrap forms.
https://github.com/maraujop/django-crispy-forms
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With