本文介绍Flask访问资源文件,下面详细介绍:
1、配置资源文件目录
class Config:
DEBUG
= False
UPLOAD_FOLDER
= 'static/uploads/'
MAX_CONTENT_LENGTH
= 100 * 1024 * 1024
}
2、启动配置
static_folder
= 'static'
app
= Flask
(__name__
, template_folder
=static_folder
, static_folder
=static_folder
)
3、访问资源文件
@client_page
.route
('/view_model', methods
=['GET'])
def view_model():
dicts
= request
.args
logging
.debug
(dicts
)
filename
= dicts
.get
('filename')
if not all([filename
]):
return jsonify
(code
=RET
.PARAMERR
, msg
=ret_map
[RET
.PARAMERR
])
if filename
:
name
= '{0}/{1}'.format(BASE_DIR
, 'static/client/3d/{0}'.format(filename
)).replace
('\\', '/')
if os
.path
.exists
(name
):
with open(name
, 'rb') as f
:
response
= make_response
(f
.read
())
return response
return jsonify
(code
=RET
.PARAMERR
, msg
=u
'文件不存在')
4、完整教程地址
Flask搭建项目完整教程:Flask+Vue搭建系统
转载请注明原文地址:https://blackberry.8miu.com/read-9127.html