I have a blueprint, home
, with the prefix /
on my Flask app. The blueprint has a static folder and is configured with the static_folder
argument. However, linking to the blueprint's static files returns a 404 error, even though the file exists and the url looks right. Why doesn't the blueprint serve the static files?
myproject/
run.py
myapp/
__init__.py
home/
__init__.py
templates/
index.html
static/
css/
style.css
myapp/init.py
:
from flask import Flask
application = Flask(__name__)
from myproject.home.controllers import home
application.register_blueprint(home, url_prefix='/')
myapp/home/controllers.py
:
from flask import Blueprint, render_template
home = Blueprint('home', __name__, template_folder='templates', static_folder='static')
@home.route('/')
def index():
return render_template('index.html')
myapp/home/templates/index.html
:
<head>
<link rel="stylesheet" href="{{url_for('home.static', filename='css/style.css')}}">
</head>
<body>
</body>
myapp/home/static/css/style.css
:
body {
background-color: green;
}