Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to use Bootstrap with Django

After some research I have the choice between two ways of integrating Bootstrap into Django.

  1. https://github.com/dyve/django-bootstrap-toolkit
  2. https://github.com/earle/django-bootstrap

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?

like image 369
Non Avatar asked Dec 21 '22 16:12

Non


1 Answers

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

like image 193
kioopi Avatar answered Dec 28 '22 07:12

kioopi