admin管理员组文章数量:1290963
In a blueprint folder hierarchy, the contents of templates
shadows the hierarchy.
Ultimately, I'd like to
- Mirror the hierarchy of blueprint
templates
in blueprintstatic
? - Add a
url_prefix
to the blueprint which applies totemplates
andstatic
,
From the folder hierachy displayed below, ./subfiles/auth
contains:
./subfiles/auth/templates/auth/register.html
./subfiles/auth/static/auth/register.js
(Note the addition of auth
after static
.)
Issue:
Even without the url_prefix
:
# auth.py
@auth_bp.route("/auth/register", methods=["GET", "POST"])
def register():
# [...]
return render_template(f"{request.path[1:]}.html")
<!-- register.html -->
<!-- [...] -->
<script src="{{ url_for( request.blueprint + ".static", filename=request.path[1:] + ".js") }}"></script>
results in:
GET http://127.0.0.1:5000/static/auth/register.js net::ERR_ABORTED 404 (NOT FOUND)
whereas:
<!-- register.html -->
<!-- [...] -->
<p>{{ url_for( request.blueprint + ".static", filename=request.path[1:] + ".js") }}</p>
results in:
/static/auth/register.js
That should be correct, although I have a feeling that it is looking at the root level ./static
rather than in ./subfiles/auth/static/
.
Folder Hierarchy:
% tree -I '__pycache__'
.
├── app.py
├── app.sh
├── blueprints_init.py
├── config.py
├── global_fun.py
├── pielection.db
├── pielection.sql
├── readme.txt
├── requirements.txt
├── static
│ ├── brand.png
│ └── styles.css
├── subfiles
│ ├── __init__.py
│ ├── auth
│ │ ├── __init__.py
│ │ ├── auth_fun.py
│ │ ├── auth_rt.py
│ │ ├── static
│ │ │ └── auth
│ │ │ └── register.js
│ │ └── templates
│ │ └── auth
│ │ ├── account.html
│ │ ├── login.html
│ │ └── register.html
└── templates
├── apology.html
├── layout.html
└── layoutmwe.html
本文标签: javascriptFlask Match folder hierarchy of static to templatesStack Overflow
版权声明:本文标题:javascript - Flask: Match folder hierarchy of `static` to `templates` - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741514951a2382829.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论