os 如何获取路径

在项目中如果想要获取绝对路径的话

要使用 os.getcwd()  在线上项目用这种方法比较多

 

@ac.route('/v1/getspecs/xdla', methods=['GET'])
def download_xdla():

    name = request.args.get('name')
    phone = request.args.get('phone')
    if Users.query.filter(Users.name == name).first() and Users.query.filter(Users.phone == phone).first():
        file_path = os.getcwd() + '/xd_project/static/说明书.docx'
        return send_file(file_path, as_attachment=True, )

    else:
        return '收集用户信息失败'

 

posted on 2018-11-07 13:57  王大拿  阅读(230)  评论(0)    收藏  举报

导航