Adding CSS files to your Flask Application - A Step-By-Step Guide

I'm working with a flask application that is functioning properly, but I would like to enhance it by incorporating my own custom CSS files.

My project structure is as follows:

my_app
    -app.py
    static/
          -style.css
    templates/
           -index.html

The content of my index.html file is:

{% extends "bootstrap/base.html" %}
{% block html_attribs %} lang="en"{% endblock %}

{% block title %} My_APP {% endblock %}

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

{% block navbar %}
<div class="navbar navbar-expand-lg navbar-dark bg-dark" style="background-color:DodgerBlue" role="navigation" >
    <div class="containter">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle"
             data-toggle="collapse" data-target=".navbar-collapse">
                <span class="sr-only">Toggle Navigation</span>
                <span class="icon-bar">Toggle Navigation</span>
                <span class="icon-bar">Toggle Navigation</span>
                <span class="icon-bar">Toggle Navigation</span>
            </button>
            <a class="navbar-brand" href="{{ url_for('home_page')  }}">ISE App</a>
        </div>
        <div class="navbar-collapse collapse">
            <ul class="nav navbar-nav">
                <li><a href="{{ url_for('home_page')  }}"> Home </a></li>
                <li><a href="{{ url_for('add_mac') }}"> Add </a></li>
                <li><a href="{{ url_for('upload_mac')  }}"> Bulk Load </a></li>
                <li><a href="{{ url_for('delete_mac') }}"> Delete </a></li>
                <li><a href="{{ url_for('bulk_remove') }}"> Bulk Remove </a></li>
            </ul>
        </div>
    </div>
</div>
{% endblock %}


{% block content %}
<div class="containter">
    <h3 id="testing">Hi how are you!!</h3>
    {% block page_content %}<h3 id="testing1">Hi how are you!!</h3>{% endblock %}
</div>
{% endblock %}

The contents of my css file named style.css include:

#testing {color:blue;}
#testing1 {color:red;}

div.containter{background-color:red}

This is what my page output looks like:

https://i.sstatic.net/czXe8.png

Despite the setup, the color scheme and background colors aren't reflecting in the output. Any insights on why my index.html isn't recognizing my stylesheet? I'm still navigating the world of flask, so any advice or suggestions would be greatly appreciated.

Answer №1

Experiment with this:

{% section preferences %}
{{parent()}}
    <link rel="stylesheet"  type="text/css" href="{{url_for('.public', filename='style.css')}}">
{% endsection %}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the technique for refining the exterior of an element while remaining within its parent container?

I need help with two elements that I have set up like this. .parent { height: 300px; width: 300px; background-image: url("https://upload.wikimedia.org/wikipedia/commons/thumb/6/6b/Icecat1-300x300.svg/2048px-Icecat1-300x300.svg.png"); backgrou ...

What is the proper way to safely escape a JSON string for an object that contains user-generated content?

How can I correctly use the variable s for the value-field of an option-element while escaping user input used for key and value? var key='highway'; var value='track'; var s = JSON.stringfy({ [key]:value }, undefined,''); s ...

Top method for identifying "abandoned words" within text that has been wrapped

Our content and design teams have a specific request to prevent paragraphs from ending with an "orphan word" - a single word on the last line of text that has wrapped onto multiple lines. The designer's proposed solution is to adjust the margins sligh ...

Why is it that when I refresh the page in Angular, my logged-in user is not being recognized? What could be causing this

I am developing a Single Page Application using the combination of Angular JS and Node JS. In my HTML file, I have defined two divs and based on certain conditions, I want to display one of them using ng-if. However, I noticed that the model value used in ...

How to customize the button color in a Next.js application

Help Needed: Issue with Changing Default Button Color in Next.JS Web Application. The button text color appears as grey on Desktop Google Chrome, but shows up as blue on Mobile Chrome browser. I want to unify the color to be grey on both platforms. Custo ...

Creating a Bootstrap form with multiple lines and a button located at the bottom right corner

I attempted to position the button at the bottom of the first container, but I am having trouble achieving this. Most examples I found have the button at the bottom of the page, which is not what I need in my case. I want to keep it within the first cont ...

Can a border-bottom be made the same size as a class it is not linked to in CSS?

Can I set a border-bottom to match the size of a separate class? For example, I want a border-bottom at the bottom of each <section> tag. However, since the sections span the full width of the screen, the border-bottom inherits that width. Each < ...

Combining existing CSS classes with node labels in Cytoscape JS for Angular: A Guide

My project follows a consistent CSS theme, but the node's CSS style doesn't match. I'm looking to adjust the label colors in the CSS based on whether it's day mode or night mode. How can I accomplish this? this.cy = cytoscape({ con ...

I am facing issues with the snap-scroll CSS feature, despite trying everything I can think of. I'm at a loss as to what the problem could be, and I suspect

I'm having trouble getting this to work properly. I can't figure out what I'm doing wrong. I've set the snap start and parent container with snap type styling in my current project using react, gatsby, and scss. Here is my code: index. ...

Issue with navigator.geolocation.getCurrentPosition not functioning again on Firefox

I've encountered a peculiar issue with JQuery that has me seeking assistance. On a certain page, I have the following block of javascript code. Upon initial page load, everything works smoothly. However, if the user navigates away and returns to the ...

What is the method to display just the final 3 characters within a paragraph?

Is there a way to display only the last three characters of a string using either a method or a string method? I consistently have a 13-digit number, but I specifically require showing only the final three digits. Appreciate any assistance provided. Than ...

Adding a stylish underline to text using HTML and CSS

Looking for some assistance with my Html and CSS website project. I am currently facing a challenge trying to place a border below the text as shown in the provided image. Below is the snippet of my Html code: <div class="Sectionheading"> ...

notification that appears when checkbox is ticked

If a certain delivery option is selected during the checkout process on our website, we would like to trigger a popup box displaying a custom message. Here is the specific checkbox for that delivery option: <input id="delivery_option_22_6" class="deliv ...

Can a jumbotron and navigation bar be permanently attached to the top of a screen?

Currently, I am in the process of constructing my website using Bootstrap and my goal is to ensure that the header and navigation bar remain fixed at the top of the page while the content below scrolls underneath. While I am aware that it is possible to fi ...

What is the process for creating a hover effect on a button that is triggered when a user hovers over the button's parent container?

Visit this link to view the code My Goal: I want the hover effect that normally applies to buttons when hovered over, to instead be applied when a user hovers over the parent div containing those buttons. The parent divs in question have a class of "ser ...

unable to see the new component in the display

Within my app component class, I am attempting to integrate a new component. I have added the selector of this new component to the main class template. `import {CountryCapitalComponent} from "./app.country"; @Component({ selector: 'app-roo ...

Chrome tab freezes when scrolling with the mouse

Working on a particularly interesting bug, I've managed to replicate it using a fiddle. The issue arises when the middle mouse button is clicked over the div element containing text, causing the pointer to become stuck. Is this possibly a browser bug ...

A <mat-card> does not have a raised appearance because it lacks a border

Looking for help with my HTML code. Here's the setup: <mat-card> <mat-card-content> <code>{{file}}</code> </mat-card-content> </mat-card> But when the mat-card element is rendered, it's not ra ...

Having Trouble with Unevenly Spaced Child Elements in CSS Flexbox?

I'm running into a problem while utilizing CSS Flexbox to design a layout with multiple child elements. The issue at hand is that the child elements are not aligning correctly within the parent container. I aim for them to be evenly distributed and ce ...

Can someone please share the steps on how to insert a new row into a PrimeNg DataTable component

I am currently working on enhancing a table by adding a new row underneath the existing data list. This new row will contain a save button and allow users to insert information, such as saving a phone number. While I have indicated where the new row should ...