Flask Tutorial – Adding Bootstrap Styles to Flask

In this Flask Tutorial, i want to show you Adding Bootstrap Styles to Flask. so there are

three different ways that you can add Bootstrap Styles in your Flask Application, that we will learn one by one.

 

 

If you are interested in Web Development with Django Framework, than you can read the

complete articles in this link,  Django Web Development Tutorials.

 

 

 

1: Adding Bootstrap Files 

the first way is that you can just create static folder in your Flask Application

working directory, download the bootstrap from getbootstrap.com, and add the files in the

static folder, and after that you need to link the CSS and JS files in your base.html.

 

 

 

So first of all this is our app.py file.

 

 

 

templates/base.html

 

 

You can see that in our base.html, we have linked our bootstrap CSS and Javascript

using this code. we have linked the CSS at the top and the Javascript at the bottom.

It is always good to add your Javascript at the bottom. and also we have added a simple

Navbar code from Bootstrap website.

 

 

 

 

 

templates/index.html

 

 

 

 

templates/contact.html

 

 

 

 

 

Now run the the Project and go to http://localhost:5000/, this will be the result.

Flask Tutorial - Adding Bootstrap Styles to Flask
Flask Tutorial – Adding Bootstrap Styles to Flask

 

 

 

 

 

2: Adding Bootstrap Library 

The second way is using Flask-Bootstrap library, Flask-Bootstrap packages Bootstrap into an extension that mostly consists of a blueprint named ‘bootstrap’. It can also create links to serve Bootstrap from a CDN and works with no boilerplate code in your application.

 

 

So first of all you need to install Flask-Bootstrap, you can use pip for the installation.

 

 

After the installation , you need to first import Flask-Bootstrap.

 

 

After that you can simply add that to your flask app.py.

 

 

 

3: Adding Bootstrap CDN Links 

The third way is so simple, you need to just copy the BootstrapCDN links from Bootstrap Website, and after that add the links for CSS, Javascript and others in your base.html like this.

 

 

 

 

Now if you run your Flask Project , the result is the same.

 

 

 

http://localhost:5000/

Flask Tutorial - Adding Bootstrap Styles to Flask
Flask Tutorial – Adding Bootstrap Styles to Flask

 

 

 

 

 

http://localhost:5000/contact

Flask Adding Bootstrap
Flask Adding Bootstrap

 

 

 

 

 

Subscribe and Get Free Video Courses & Articles in your Email

 

Share via
Copy link
Powered by Social Snap
×