flask报错WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
# encoding:utf-8
from flask import Flask, request, jsonify
from flask_sqlalchemy import SQLAlchemy
from text_analysis.code import get_top_positive_negative_frequency
from utils import get_data,get_db_config
from gevent import pywsgi
app = Flask(__name__)
# 连接数据库
config = get_db_config()
app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://{}:{}@{}:3306/{}'.format(config["user"],config["password"],config["host"],config["database"])
# 实例化orm框架的操作对象,后续数据库操作,都要基于操作对象来完成
db = SQLAlchemy(app)
# 声明模型类
class User(db.Model):
__tablename__ = "tb_user" # 设置表名
id = db.Column(db.INTEGER, primary_key=True)
username = db.Column(db.String(16), nullable=False)
password = db.Column(db.String(16), nullable=False)
@app.route('/')
def hello_world():
return 'Hello World!'
@app.route("/login", methods=["post"])
def login():
"""登录"""
code, msg = 200, "success"
username = request.json.get("username")
password = request.json.get("password")
if not username or not password:
code, msg = 500, "用户名或者密码不能为空"
if not User.query.filter_by(username=username, password=password).first():
code, msg = 500, "密码错误"
return jsonify({"msg": msg, "code": code})
@app.route("/regist", methods=["post"])
def regist():
"""注册"""
code, msg = 200, "success"
username = request.json.get("username")
password = request.json.get("password")
if username and password:
if User.query.filter_by(username=username).first():
msg = "用户%s已存在" % username
else:
new_user = User(username=username, password=password)
db.session.add(new_user)
db.session.commit()
return jsonify({"msg": msg, "code": code})
@app.route("/display", methods=["post"])
def display():
"""
获取绘图数据
:return:
"""
code, msg = 200, "success"
url = request.json.get("url")
username = request.json.get("username")
top = request.json.get("top", 10)
product_id = url.split('id=')[-1] if url.split('id=') else url
data = get_data(username, product_id)
data.update(get_top_positive_negative_frequency(data, top))
data.pop("comments")
return jsonify({"msg": msg, "code": code, "data": data})
if __name__ == '__main__':
db.create_all()
app.run(host="0.0.0.0")
这只是警告,不是报错,不影响你正常使用的。意思是说你现在的环境是开发环境,建议用生产环境代替,生产环境。flask自带一个web服务,但是这个web服务器性能比较差,只能适合自己开发的时候使用,所以通过flask run 会启动flask 自己的web服务器,导致系统会提示这是一个开发的服务器。
诶没有报错哇,这只是一个警告来着。你以后的开发过程中会不停的遇到警告