Python Flask框架常用组件介绍

数据库

连接mysql必要依赖

ubuntu

sudo apt-get install libmysqlclient-dev

centos

yum install -y mysql-devel gcc gcc-devel python-devel
pip install flask-mysqldb -i https://pypi.douban.com/simple

否则报错 没有包 MySqldb

1 允许跨域请求

pip install flask-cors

1.1 全局方式

from flask_cors import *
app = Flask(__name__)

CORS(app, supports_credentials=True)

@app.route('/')
@cross_origin()
def index():
	return 'Hello World'

1.2 独立方式

from flask_cors import *
app = Flask(__name__)

@app.route('/')
@cross_origin()
def index():
	return 'Hello World'

你可能感兴趣的:(python,flask,python,后端)