Python 多个静态文件夹&;flask应用程序中的模板文件夹
flask应用程序中是否可能有多个静态文件夹?我有一些.css和.js文件,我只对某些blueprint使用它们,并且希望这些文件与blueprint位于同一目录中 我的应用程序的结构如下:Python 多个静态文件夹&;flask应用程序中的模板文件夹,python,python-3.x,flask,project-structure,Python,Python 3.x,Flask,Project Structure,flask应用程序中是否可能有多个静态文件夹?我有一些.css和.js文件,我只对某些blueprint使用它们,并且希望这些文件与blueprint位于同一目录中 我的应用程序的结构如下: app | | blueprints | | | | blueprint_1 | | | | | | views.py | | | __init__.py | | | | blueprint_2 | | | | | | views.py | | | __init__.py | | static | |
app
|
| blueprints
| |
| | blueprint_1
| | |
| | | views.py
| | | __init__.py
| |
| | blueprint_2
| | |
| | | views.py
| | | __init__.py
|
| static
| |
| | css, js, etc.
app
|
| blueprints
| |
| | blueprint_1
| | |
| | | views.py
| | | __init__.py
| | | static
| | | |
| | | | certain css, js, etc
| |
| | blueprint_2
| | |
| | | views.py
| | | __init__.py
| | | static
| | | |
| | | | certain css, js, etc
|
| static
| |
| | css, js, etc.
我希望有这样的结构:
app
|
| blueprints
| |
| | blueprint_1
| | |
| | | views.py
| | | __init__.py
| |
| | blueprint_2
| | |
| | | views.py
| | | __init__.py
|
| static
| |
| | css, js, etc.
app
|
| blueprints
| |
| | blueprint_1
| | |
| | | views.py
| | | __init__.py
| | | static
| | | |
| | | | certain css, js, etc
| |
| | blueprint_2
| | |
| | | views.py
| | | __init__.py
| | | static
| | | |
| | | | certain css, js, etc
|
| static
| |
| | css, js, etc.
和模板类似。
当我在模板中使用.js文件时,我通过以下方式访问它:
{{url\u for('static'),filename='jsfile'}}
好的,我想出来了
根据,如果蓝图没有url_前缀,则无法访问蓝图的静态文件夹
因此,解决办法是:
将url_前缀添加到蓝图:
some\u blueprint=blueprint('something'、\u name\u、static\u folder='static',url\u prefix='/something')
在模板中,我们引用静态文件夹,如下所示:
{{url\u for('something.static',filename=…)}
这对我来说似乎有点奇怪,url_前缀是它工作所必需的,但不管怎样。使用多个资产文件夹的示例应用程序: