url_for: how to look into another folder other than static

半世苍凉 提交于 2019-12-12 13:49:37

问题


I have a file test.css in a folder called css. I want to create url for this file. I know that I can use url_for like

url_for('static', filename="test.css")

to create url like static/test.css but I am not able to use like

url_for('css', filename="test.css")

to create the url that I am interested in css/test.css

How can I do this?


回答1:


static just endpoint, see route and view. So you can create own endpoints:

app.add_url_rule('/css/<path:filename>', endpoint='css',
                 view_func=app.send_static_file)



回答2:


I think (I can't test here right now) you can do

url_for('/', filename='css/test.css')

However, since CSS files are also static, I would make a subdirectory css under static, and then do

url_for('static', filename='css/test.css')


来源:https://stackoverflow.com/questions/18249527/url-for-how-to-look-into-another-folder-other-than-static

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!