0

I want to build a site. I have the index folder and the connected folder. Each folder also has a static folder. In the connected/static folder, I have the connected.css file, which I am trying to access, through my blueprint. However, the final page tries to access the connected.css from the index/static folder.

Where am I mistaking?

Useful code:

__init__.py:

from flask import Flask
from .index import index_routes
from .connected import connected_routes


def create_app():
    app = Flask(__name__, template_folder="templates", static_folder="static")
    app.register_blueprint(index_routes.index_bp)
    app.register_blueprint(connected_routes.connected_bp, url_prefix='/connected')
    return app

connected_routes.py

from flask import Blueprint
from flask import render_template

connected_bp = Blueprint('connected_bp', __name__, template_folder='templates', static_folder='static', url_prefix='/connected')  

@connected_bp.route('/')
def connected():
    return render_template('connected.html', title="Connected to Hattrick")

index_routes.py

from flask import Blueprint
from flask import render_template

index_bp = Blueprint('index_bp', __name__, template_folder='templates', static_folder='static')


@index_bp.route('/')
def home():
    return render_template('index.html', title="The Best Match Predictor")

connected.html

<link href="{{url_for('static',filename='connected.css')}}" rel="stylesheet">

In the above line I have the problem.

1 Answer 1

1

Maybe give this a try:

<link href="{{url_for('connected.static',filename='connected.css')}}" rel="stylesheet">

For some elaboration: https://flask.palletsprojects.com/en/1.1.x/blueprints/#static-files

Sign up to request clarification or add additional context in comments.

2 Comments

Actually, it's connected_bp.static and it worked. Thank you!
No problem, and yes my bad, the url_prefix is to make the endpoint accesible. The blueprint name is used in url_for

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.