Django and Bootstrap: What app is recommended?

PythonDjangoTwitter Bootstrap

Python Problem Overview


I want to start using Twitter's Bootstrap for a recently started Django app. I have quite a bit of experience with Django, but I'm totally new to Bootstrap.

What's the best way to proceed? Are there any particular Boostrap apps for Django you would recommend or have experience with?

I understand that I could use Bootstrap directly, without any special Bootstrap-specific Django apps. However, I also read that the form rendering doesn't come out particularly well without a little server side support (rendering the Bootstrap specific CSS into the form HTML, for example).

There seem to be several projects, such as crispy forms, django-bootstrap-toolkit, etc. Looking at their project pages, I can see different levels of activity and support. If I decide to go with one of those, I would of course like to pick one which has some momentum and therefore a good likelihood of staying supported and maintained for a while. This is very important and so even if the particular app doesn't have all possible features or is a bit less flexible, it might still be a good choice, due to support/freshness, availability of examples, etc.

Thank you for any recommendations or feedback.

Python Solutions


Solution 1 - Python

I used django-bootstrap-toolkit — as the author explains (with reference to other Django/Bootstrap integration apps)

> "The approach to template tags and filters seemed right, but Bootstrap does so much more than just forms."

In addition to forms, then (which can be as simple as {% form|as_bootstrap %}, this app helps with pagination, inserting static URLs to the Bootstrap media files, and some other bits. Read templatetags/bootstrap-toolkit.py for the full list.

@dolan notes that the django-bootstrap-toolkit developer recommends a new project for Bootstrap v3 support, django-bootstrap3. I haven't tried this yet as I haven't started a new project since V3 came out, so YMMV.

Solution 2 - Python

I've been using django-crispy-forms with bootstrap for the last couple of months and it has been quite useful. Forms render exactly as they're meant to. If you do any custom form rendering though, be prepared to define your forms in code rather than in template, using helpers.

Solution 3 - Python

Another option to consider is django-bootstrap-form.

I found crispy-forms to be too heavyweight for my needs. Django-bootstrap is not maintained any more. I tried django-bootstrap-toolkit and django-bootstrap-form, and while it does look like django-bootstrap-toolkit has more features, I found my needs were met by django-bootstrap-form. In the interest of keeping things simple, I chose the latter, and haven't found it lacking (although I'd be interested to hear other opinions on their relative merits).

In addition to django-bootstrap-form, I'd recommend django-widget-tweaks, which allows you to add classes (and other attributes) to your forms using template filters, e.g.:

{{ form.field|add_class:"input-small" }}

This lets you use class-based formatting from Bootstrap while keeping the presentation logic in the template.

Solution 4 - Python

I've been using django-bootstrap. No complaints so far.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionjbrendelView Question on Stackoverflow
Solution 1 - PythonsupervacuoView Answer on Stackoverflow
Solution 2 - PythonJosh SmeatonView Answer on Stackoverflow
Solution 3 - PythonSymmetricView Answer on Stackoverflow
Solution 4 - Pythonsuper9View Answer on Stackoverflow