3 Star 0 Fork 0

zhangwenlong/flask-vue-master

Create your Gitee Account
Explore and code with more than 12 million developers,Free private repositories !:)
Sign up
文件
Clone or Download
plugins.py 2.06 KB
Copy Edit Raw Blame History
zhangwenlong authored 2024-02-15 15:09 . 2024-2-15初始化仓库
import logging
from flask import jsonify
from flask_jwt_extended import JWTManager
from flask_mail import Mail
from flask_migrate import Migrate
from flask_sqlalchemy import SQLAlchemy
from flask_restful import Api
from flask_cors import CORS
from sqlalchemy import create_engine
import config.config
api = Api()
db = SQLAlchemy()
migrate = Migrate()
jwt = JWTManager()
cors = CORS(origins="*")
mail = Mail()
'''
origins = "*" 允许所有访问源跨域
resources 允许跨域的接口
from flask_cors import cross_origin
@cors.crossdomain(origin="*") @cross_origin() 这两个装饰器加在某个接口上表示只允许这个接口允许跨域请求
'''
def init_plugins(app):
migrate.init_app(app=app, db=db)
jwt.init_app(app=app)
api.init_app(app=app)
logging.Formatter("%(pastime)s %(name)s %(filename)s %(funcName)s %(lineno)d %(message)s", datefmt='%Y-%m-%d '
'%H:%M:%S')
db.init_app(app=app)
# 配置Flask-Mail
app.config['MAIL_SERVER'] = config.config.MAIL_SERVER
app.config['MAIL_PORT'] = config.config.MAIL_PORT
app.config['MAIL_USE_TLS'] = config.config.MAIL_USE_TLS
app.config['MAIL_USE_SSL'] = config.config.MAIL_USE_SSL
app.config['MAIL_USERNAME'] = config.config.MAIL_USERNAME
app.config['MAIL_PASSWORD'] = config.config.MAIL_PASSWORD
app.config['MAIL_DEFAULT_SENDER'] = config.config.MAIL_DEFAULT_SENDER
mail.init_app(app=app)
cors.init_app(app=app)
@jwt.invalid_token_loader
def invalid_token_callback(error_string):
# 处理无效 token 的逻辑
return jsonify({"message": "Invalid token", "error": error_string}), 401
# 注意:返回的是一个字典,而不是一个函数引用
@jwt.unauthorized_loader
def unauthorized_callback(error_string):
# 处理没有提供 token 的逻辑
return jsonify({"message": "Missing token", "error": error_string}), 401
# 注意:返回的是一个字典,而不是一个函数引用
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/Java_SSM/flask-vue-master.git
git@gitee.com:Java_SSM/flask-vue-master.git
Java_SSM
flask-vue-master
flask-vue-master
1.1

Search

0d507c66 1850385 C8b1a773 1850385