Reputation: 434
Have a file structure as follows:
app.py and app2.py are nearly identical, except app2.py directs to the templates folder due to app2.py being in the \src folder.
app.py:
app2.py:
When loading via app.py, everything runs fine and the main.css is found. However, when running app2.py (inside the src directory), flask can't find the main.css and returns an error: "
GET /static/css/main.css HTTP/1.1" 404 -
Not sure what's going on as the files are nearly identical.
Index.html
{% extends 'base.html' %}
{% block head %}
{% endblock %}
{% block body %}
<h1> Template </h1>
{% endblock %}
base.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="{{url_for('static', filename='css/main.css') }}">
{% block head %}{% endblock %}
</head>
<body>
{% block body %}
{% endblock %}
</body>
</html>
Upvotes: 0
Views: 365
Reputation: 1
just remove css/ from this code line it is working in my case
<link rel="stylesheet" href="{{url_for('static', filename='main.css') }}">
Upvotes: 0
Reputation: 645
In this case you also need to pass the static
-folder location:
app = Flask(__name__, template_folder='../templates', static_folder='../static')
Upvotes: 1