James Huang
James Huang

Reputation: 876

Style tag in Flask doesn't render the text color

I have template html that is using bootstrap. Here is the code:

{% extends "base.html" %}
{% block title %}{{session.name}}{% endblock %}
{% block content%}
    <h4>Name: <span class="value">{{session['name']}} </span></h4>
    <h4>Email: <span class="value">{{session['email']}}</span></h4>
    <h4>Password: <span class="value">{{session['password']}}</span></h4>
{% endblock %}
<style>
    .value{
        color: blue;
    }
</style>

My problem is that the .value classes are not being rendered as blue and I don't know why. What is causing this?

Upvotes: 0

Views: 309

Answers (2)

Md Irshad
Md Irshad

Reputation: 19

Within the block you should write your contents because you can later on use it as components. Even though you should consider using the style within the head of your html index page. If you use style within head of html it will assure your styles will be loader before the elements will be displayed which will not break your stylings.

Upvotes: 0

James Huang
James Huang

Reputation: 876

After some tinkering around with the code, this became my solution:

{% extends "base.html" %}
{% block title %}{{session.name}}{% endblock %}
{% block content%}
    <h4>Name: <span class="value">{{session['name']}} </span></h4>
    <h4>Email: <span class="value">{{session['email']}}</span></h4>
    <h4>Password: <span class="value">{{session['password']}}</span></h4>
    <style>
        .value{
            color: blue;
        }
    </style>
{% endblock %}

The style has to be inside the block. It seems that the block is rendered before the style was being taken into account, so it was having no effect.

Upvotes: 2

Related Questions