提供位于Flask蓝图文件夹下的静态文件

Ste*_*hen 3 python flask

我有一个包含模板和静态文件的Flask蓝图.模板正确呈现,但链接的CSS文件返回404未找到.如何提供位于蓝图文件夹下的静态文件?

app/
  __init__.py
  auth/
    __init__.py
    static/
      style.css
    templates/
      index.html
Run Code Online (Sandbox Code Playgroud)
auth = Blueprint('auth', __name__, template_folder='templates')

@auth.route('/')
def index():
    return render_template('index.html')
Run Code Online (Sandbox Code Playgroud)
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='style.css') }}">
Run Code Online (Sandbox Code Playgroud)

dav*_*ism 5

通过传递告诉蓝图其静态文件夹的位置static_folder,然后用于url_for生成static蓝图上的路径的URL .这在文档中描述.

auth = Blueprint('auth', __name__, template_folder='templates', static_folder='static')
Run Code Online (Sandbox Code Playgroud)
url_for('auth.static', filename='style.css')
Run Code Online (Sandbox Code Playgroud)