How to use Python and Bootstrap for Web Development

When you want to make a website good looking, you turn to CSS. There is no better way than that. Because there are many intricacies with CSS, developers have come up with ways to package ‘styles’. The most common choice is Bootstrap, originally developed by and for Twitter. This is not, at all, the only CSS framework so you will see more in this article.

Django Bootstrap

When programming in Python, you would typically use a web framework, one very common one is Django. Fortunately, there is a project for using Bootstrap in Django. This is on so installing is the regular routine. Most likely you are running a virtual environment, activate it and install with pip.

$ pip install django-bootstrap3

The same team supports Bootstrap4, that project has a coverage rating of 89% so your particular feature may be missing. You have to make that decision yourself. Now, you need to add this application to your ‘’ file.


Now, you can use Bootstrap in your site code. Since you are using Django, you have a templates directory defined in your ‘’ file. In the main template, add the below code.

{% load bootstrap3 %}
<form action="/your/url" method="post" class="form">
{% bootstrap_form form %}
{% buttons %}
<button type="submit" class="btn btn-primary">
{% bootstrap_icon "star"%} SUBMIT
{% endbuttons %}

The two values in this code that is interesting are “bootstrap*”, these are template tags and filters that you can lookup how to use in the Django-Bootstrap documentation. The {% buttons %} code can also include parameters that determine the text for submitting and resetting the form. When you get more advanced, make sure you add BOOTSTRAP3 to your There are also templates for errors and messages that you can use to control how errors display on your website.

Flask Bootstrap

In Flask you also have a module called Flask-Bootstrap, this is installed in your virtual environment using PIP as usual.

$ pip install flask-bootstrap

The module works very similarly, not surprisingly since they both use the Jinja2 templates engine. The import is a more direct way of using the bootstrap functions so you need to import the module in the top of your ‘’ file. You need to add Bootstrap to your ‘app’ definition in the same file.

from flask import Flask
from flask_bootstrap import Bootstrap
def create_app():
    app = Flask(__name__)
    return app

When you have this imported you just need to add it to your templates the same way you would in a regular website. The difference is that you have blocks that define how the different pieces on your website looks. Go through the blocks you have available on their website. Otherwise, you call the framework the same way you would in Django. There are many macros available, i.e. WTForms support.

Other choices

You also have similar projects for cubicweb, called cubicweb-bootstrap. The install is as usual, pip install. It contains the whole library and some routines to use it.

If you don’t find a solution that suites you, investigate what Fanstatic can help you with. It creates ways to import JavaScript dependencies into you Python code. This also works with CSS files. This framework is made to leverage any WSGI compliant web framework so look into this for your specific needs.


If you want to use CSS to brighten your website, the most efficient way is to use an existing framework. The interface to those frameworks are already there, just put your styling in your templates and your good to go. Python and most frameworks available have powerful routines for databases, CSS and many other things that will keep you in control and also let you create amazing things quickly an efficiently.

Reference list:

Sandclock IDC thành lập vào năm 2012, là công ty chuyên nghiệp tại Việt Nam trong lĩnh vực cung cấp dịch vụ Hosting, VPS, máy chủ vật lý, dịch vụ Firewall Anti DDoS, SSL… Với 10 năm xây dựng và phát triển, ứng dụng nhiều công nghệ hiện đại, Sandclock IDC đã giúp hàng ngàn khách hàng tin tưởng lựa chọn, mang lại sự ổn định tuyệt đối cho website của khách hàng để thúc đẩy việc kinh doanh đạt được hiệu quả và thành công.
Bài viết liên quan

How to Calculate Matrices in Python Without NumPy

For many applications, you need mathematics. In Python there is the maths module which handles the basics such as rounding,...

GUI Automation using Pyautogui, Python

PYAUTOGUI is an automation module provided by Python for controlling keyboard and mouse functions via program. This module...

Python QR Code generator

What are QR codes? QR codes are some of the fastest-growing trends in today’s world when it comes to sharing any sort...
Bài Viết

Bài Viết Mới Cập Nhật

Hướng dẫn chuyển đổi windows server windows evaluation to standard và active windows server 2008 + 2012 + 2016 + 2019

How to Update Ubuntu Linux

Squid Proxy Manager cài đặt và quản lý Proxy Squid tự động trên ubuntu

Hướng dẫn cài đặt Apache CloudStack

Hướng dẫn ký file PDF bằng chữ ký số (chữ ký điện tử) và sửa lỗi mới nhất 2021 foxit reader