Я пытался следовать этому учебнику , в котором показано, как изменить расположение статической папки и папки шаблона в корневом каталоге.Однако я не могу заставить пример работать.Приложение работает нормально, но возвращает 404, когда ищет таблицу стилей «GET /static/style.css HTTP / 1.1» 404. Поэтому кажется, что оно может найти шаблон, но не таблицу стилей.
Здравствуйте!пример мира здесь и ниже.Должен ли я использовать root_path, а может быть instance_path или template_folder и static_folder?
api_files
static
style.css
templates
index.html
api.py
api.py из колбы для импорта 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;
}