依赖包文件:
[[source]]
name = “pypi”
url = “
Simple index”
verify_ssl = true
[dev-packages]
[packages]
flask = “"
flask-script = "”
flask-migrate = “"
flask-login = "”
flask-wtf = “"
requests = "”
flask-openid = “"
flask-mail = "”
python-alipay-sdk = “"
flask-socketio = "”
pymysql = “"
eventlet = "”
[requires]
python_version = “3.6”
——————————————————————————————————
初始化文件:
from flask import Flask
from flask_socketio import SocketIO
from apps import config
from flask_mail import Mail
from apps.models.base import db
from flask_login import LoginManager
import apps.models.data
from os.path import dirname, join
def create_app():
app = Flask(name)
app.config.from_object(“apps.config”)
db.init_app(app)
socketio.init_app(app)
login_manager.init_app(app)
login_manager.login_view = ‘home.login’
with app.app_context():
db.create_all()
from apps.website.home import home_bp
from apps.website.auth import auth_bp
from apps.website.chat import chat_bp
from apps.website.pay import pay_bp
from apps.server.admin import admin_bp
app.register_blueprint(home_bp)
app.register_blueprint(admin_bp, url_prefix=“/server”)
app.register_blueprint(auth_bp, url_prefix=‘/auth’)
app.register_blueprint(chat_bp, url_prefix=‘/chat’)
app.register_blueprint(pay_bp, url_prefix=‘/pay’)
return app
mail = Mail()
socketio = SocketIO()
login_manager = LoginManager()
login_manager.session_protection = ‘strong’
——————————————————————————————————————
启动文件:
from apps import create_app, db,socketio
from flask_script import Manager
from flask_migrate import Migrate, MigrateCommand
app = create_app()
manager = Manager(app)
migrate = Migrate(app, db)
manager.add_command(‘db’, MigrateCommand)
if name == ‘main’:
socketio.run(app)
——————————————————————————
关闭DEBUG调试:
关闭DEBUG能正常连接,就是提示使用的是内置开发服务器。
————————————————————————————
开启DEBUG 调试
错误:
handler = _signal.signal(_enum_to_int(signalnum), _enum_to_int(handler))
ValueError: signal only works in main thread