70

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.

4 Answers 4

51

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.

Sign up to request clarification or add additional context in comments.

6 Comments

Good comment ... Bootstrap is way much more than just forms ..
So far, django-bootstrap-toolkit is working out well for me.
FYI: The developer of django-bootstrap-toolkit recommends a separate project for Bootstrap v3 support: github.com/dyve/django-bootstrap3
supervacuo, what is the advantage of this plugins over just importing bootstrap and adding the css classes?
@AlexanderSuraphel Less typing; see the django-bootstrap3 documentation for examples: django-bootstrap3.readthedocs.org/en/latest/quickstart.html
|
6

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.

2 Comments

Thank you for the response. I have heard "Bootstrap does more than just forms!". Do you find crispy-forms to be restrictive in some way, preventing you from easily using other Bootstrap features? Or - in your experience - is 'forms' really the only thing for which you require server side support for Bootstrap?
@jbrendel bootstrap is mainly just css and html (with a sprinkling of js) - most of which is handled directly by your templates. Forms, however, generate html within python. There has been a GSOC project aiming to generate forms using templates, but has not progressed very well. So I only really see the need for help with forms - as defining your templates is a manual process anyway. Saying that, I haven't looked in to other server side bootstrap helpers, so I don't know where they help.
6

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.

Comments

3

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

1 Comment

This project is no longer maintained. Use django-crispy-forms instead.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.