参考文档
app.py
from flask import Flask from flask import jsonify from flask_cors import CORS import pymysql # # # # 搜索 更新下载 @app.route("/updateCountSearch/<id>/<num>") def updateCountSearch(id, num): cursor.execute("update manypic set count=" + num + " where id = '" + id+"'") db.commit() return jsonify([{'res': 'success'}]) # 程序的入口 if __name__ == "__main__": db = pymysql.connect( host="39.xx.xx.37", # 主机 port=3306, # 端口 db="spider", # 数据库名 user="root", # 用户名 passwd="xxx", # 密码 charset="utf8" ) # 创建cursor cursor = db.cursor(cursor=pymysql.cursors.DictCursor) # 解决flask中文乱码 app.config['JSON_AS_ASCII'] = False # 调试模式 # port 端口号 默认5000 app.run(debug=True, port=8080, host="0.0.0.0")
requirements.txt
Flask==1.1.2 Flask-Cors==3.0.10 PyMySQL==0.10.1
FROM python:3.7 RUN mkdir /code WORKDIR /code ADD requirements.txt /code/ RUN pip install -r requirements.txt ADD . /code
version: "3.3" services: web: build: . command: python3 ./app.py runserver 0.0.0.0:8080 ports: - "8080:8080"
docker-compose up -d