[FIXED] Using flask_bootstrap and cant seem to over ride CSS,


I can’t seem to get the CSS to override the bootstrap CSS. I have done a very clear change while trying to get it to work by changing the body background color.

My working dir

End result

This is my Main.py

from flask import Flask, render_template
from flask_bootstrap import Bootstrap
from flask_wtf import FlaskForm
from wtforms import PasswordField, StringField, SubmitField
from wtforms.validators import InputRequired, Length

app = Flask(__name__)
app.config['SECRET_KEY'] = 'secret key'

class LoginForm(FlaskForm):
    username = StringField(label="Username", validators=[InputRequired()])
    password = PasswordField(label="Password", validators=[InputRequired(), Length(8)])
    submit = SubmitField(label="Login")

def home():
    return render_template("index.html")

@app.route("/login", methods=['GET', 'POST'])
def login():
    login_form = LoginForm()
    return render_template("login.html", form=login_form)

if __name__ == "__main__":

This is the HTML for the login page.

{% extends "bootstrap/base.html" %}
{% import "bootstrap/wtf.html" as wtf %}

{% block styles %}
  <link rel="stylesheet" type="text/css" href="{{url_for('.static', filename='static/css/mystyle.css')}}">
{% endblock %}

{% block content %}
<div class="container">
    {{ wtf.quick_form(form) }}
{% endblock %}

And this is my CSS

body {
  background-color: lightblue;

.middle {
  align-items: center;
  height: 100%;


The static endpoint expects a path (filename value) relative to the root of the static folder. Just remove the leading static/ part in your path:

{{ url_for('static', filename='css/mystyle.css') }}

And no need to add a dot before the endpoint.

Answered By – Grey Li

Answer Checked By – Clifford M. (Easybugfix Volunteer)

Leave a Reply

(*) Required, Your email will not be published