I tried following a tutorial which intends to demonstrate how to change the location the static and template folder from being in the root directory. However I cannot get the example to work. The application runs fine but returns a 404 when it looks for the stylesheet "GET /static/style.css HTTP/1.1" 404. So it seems like it can find the template but not the stylesheet.
My hello world example is below. Should I be using root_path, or maybe instance_path or template_folder and static_folder?
api_files
static
style.css
templates
index.html
api.py
api.py from flask import Flask, render_template, url_for
# here we can set a different root path
app = Flask(__name__, root_path='api_files/')
@app.route('/')
def index():
"""Render home page."""
return render_template('index.html') # we can render templates as usual
if __name__ == '__main__':
app.run(debug=True)
index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<link rel= "stylesheet" type= "text/css" href= {{ url_for('static', filename='style.css') }}>
</head>
<body>
hello world
</body>
</html>
style.css
body {
color: red;
}