我实际上在笔记本电脑上更改了驱动程序,并安装了python 3.7的最新版本,我安装了python 3.7,并安装了我主要使用的所有flask模块。但是当我运行旧项目时,出现了AttributeError: 'Blueprint' object has no attribute 'teardown_appcontext'
错误,我不知道该如何解决,我也试图寻找解决方案,但仍然没有帮助。
更多信息是实际错误:
回溯(最近通话最近): 在第33行的文件“ app.py”中 从蓝图导入* 在第7行的文件“ / Users / kim / Documents / Python / WebApp Projects / joannets / blueprints / init .py”中 从blueprints.routes.index导入APP_BLUEPRINT_INDEX 文件“ / Users / kim / Documents / Python / WebApp Projects / joannets / blueprints / routes / index.py”,第6行 缩小(APP_BLUEPRINT_INDEX) init 中的文件“ /Users/kim/Documents/env/lib/python3.8/site-packages/flask_minify/main.py”,第64行 app和self.init_app(app) init_app中的文件“ /Users/kim/Documents/env/lib/python3.8/site-packages/flask_minify/main.py”,第87行 app.teardown_appcontext(self.teardown) AttributeError:“蓝图”对象没有属性“ teardown_appcontext”
这是主要的app.py:
import os
import yaml
import datetime
from flask import Flask, render_template
from flask_mysqldb import MySQL
from flaskwebgui import FlaskUI
APPLICATION = Flask(__name__)
APPLICATION.secret_key = "J0@nNeTrucKinG53rvic3S"
# Get the directory folder name
def directory():
return os.path.dirname(os.path.abspath(__file__))
# Join the Directory name with the path target
def fileInclude(joinPath):
return os.path.join(directory(), joinPath)
# Open the yaml database configure file
dbConfig = yaml.load(open(fileInclude("config/dbconfig.yaml")), Loader = yaml.FullLoader)
APPLICATION.config["MYSQL_HOST"] = dbConfig["DB_HOST"]
APPLICATION.config["MYSQL_DB"] = dbConfig["DB_DATABASE"]
APPLICATION.config["MYSQL_USER"] = dbConfig["DB_USERNAME"]
APPLICATION.config["MYSQL_PASSWORD"] = dbConfig["DB_PASSWORD"]
APPLICATION.config["MYSQL_CURSORCLASS"] = "DictCursor"
_DATABASE_ = MySQL(APPLICATION)
from blueprints import *
"""
It will handle the URL error
if the request of page not found.
"""
@APPLICATION.errorhandler(404)
def PAGE_NOT_FOUND(error):
return render_template("/404/index.html")
"""
This injection function will help
to create a local variable to use in templates.
"""
@APPLICATION.context_processor
def INJECT_SUB_HELPERS():
return {"COMPANY": "",
"DATEYEAR": datetime.datetime.now().strftime("%Y")}
if __name__ == "__main__":
# INTEND TO USE THIS FRO PRODUCTION
UI = FlaskUI(APPLICATION)
UI.run()
# FOR DEBUGGING
# APPLICATION.run(debug = True)
这是我存储了所有蓝图模块的蓝图文件:
"""
Register all blueprints frame / routes here
"""
from app import APPLICATION
from blueprints.routes.index import APP_BLUEPRINT_INDEX
from blueprints.routes.login import APP_BLUEPRINT_LOGIN
from blueprints.routes.vehicles import APP_BLUEPRINT_VEHICLE
from blueprints.routes.drivers import APP_BLUEPRINT_DRIVERS
from blueprints.routes.twogo import APP_BLUEPRINT_2GO
from blueprints.routes.tanduay import APP_BLUEPRINT_TANDUAY
from blueprints.routes.laplap import APP_BLUEPRINT_LAPLAP
APPLICATION.register_blueprint(APP_BLUEPRINT_LOGIN)
APPLICATION.register_blueprint(APP_BLUEPRINT_INDEX)
APPLICATION.register_blueprint(APP_BLUEPRINT_VEHICLE)
APPLICATION.register_blueprint(APP_BLUEPRINT_DRIVERS)