Bootstrap with Flask

Jay Ocean picture Jay Ocean · Dec 31, 2016 · Viewed 18.2k times · Source

I am looking to integrate a bootstrap template into my flask program. Specifically: I downloaded the zip file for this template:

https://startbootstrap.com/template-overviews/sb-admin/

However, the file is in a completely different format from the Flask template/static format.

I also downloaded Flask-Bootstrap (python) but have not been able to successfully import the template accurately.

I am looking for advice on how to easily import this type of template into my flask code (including css, jQuery, html, etc.). Thanks!

Answer

Amin Alaee picture Amin Alaee · Jan 1, 2017

You need to create templates and static folders in your project folder, put all .html files in templates folder and all other files (CSS, JS, JPG, etc) in static folder and then in your html file use url_for to load the static files, instead of the default HTML way.

This is a sample project structure:

-project
    app.py
    - templates
        index.html
    -static
        -css
          style.css
        -js
          example.js
        -img 
          example.jpg
  • You can also use custom folders and structure but you need to define them while creating the application instance Docs