python - flask 调试的时候,不另开 httpserver 怎样提供静态文件?
高洛峰
高洛峰 2017-04-17 13:56:46
0
1
338

类似 django.views.static.serve , 在 flask 下通常是怎么做的.

高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

reply all(1)
大家讲道理

I don’t know what effect django.views.static.serve is. I hope the following content will be helpful to you.

In the Flask development environment, I mainly use the following two methods to access static files:

【Method 1】

Put the static files in the static directory. For example, if the application has a static file in the css/style.css directory, it can be accessed through the /static/css/style.css URL.

【Method 2】

Use the send_from_directory function. For example:

python@app.route('/robots.txt')
def robotstxt():
    return send_from_directory(app.static_folder, 'robots.txt')

The first parameter is the directory, which can be specified flexibly. The static directory is used here for convenience; the second parameter is the file name. See the documentation for more details.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template