CentOS7 安装 anaconda flask验证

参考 

 

yum -y groupinstall "Development tools"

yum install openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel

wget https://repo.anaconda.com/archive/Anaconda3-2019.03-Linux-x86_64.sh

bash Anaconda3-2019.03-Linux-x86_64.sh     一直 enter 和 yes 



[root@hdp1 yum.repos.d]# source ~/.bashrc

  

验证

(base) [root@hdp1 yum.repos.d]# pip -V
pip 19.0.3 from /root/anaconda3/lib/python3.7/site-packages/pip (python 3.7)

(base) [root@hdp1 yum.repos.d]# python
Python 3.7.3 (default, Mar 27 2019, 22:11:17)

  

(base) [root@hdp1 ~]# cat flask_demo.py 
from flask import Flask

app = Flask(__name__)


@app.route('/')
def hello_world():
    return 'Hello World!'


if __name__ == '__main__':
    app.run(host='0.0.0.0',port=9230)

 启动flask

 

(base) [root@hdp1 ~]# python flask_demo.py 
 * Serving Flask app "flask_demo" (lazy loading)
 * Environment: production
   WARNING: Do not use the development server in a production environment.
   Use a production WSGI server instead.
 * Debug mode: off
 * Running on http://0.0.0.0:9230/ (Press CTRL+C to quit)

 

  

 

 

 

 

把文件以接口形式对外提供下载和浏览

(base) [root@hdp1 ~]# cat get_file.py 
# -*- coding: utf-8 -*-
from flask import Flask, render_template, send_file, send_from_directory, json, jsonify, make_response
 
app = Flask(__name__)  #实例化flask app
 
#file_name是客户端传来的需要下载的文件名
@app.route('/get_file/<file_name>', methods=['GET'])
def get_file(file_name):
    directory = "/root/"
    try:
        response = make_response(
            send_from_directory(directory, file_name, as_attachment=True))
        return response
    except Exception as e:
        return jsonify({"code": "异常", "message": "{}".format(e)})
 
if __name__ == '__main__':
    app.run(debug=False, host='0.0.0.0', port=8011)

 

 

 

 

 

  

 

posted on 2022-06-03 00:31  寒星12345678999  阅读(71)  评论(0编辑  收藏  举报