Flask注册蓝图出现:AttributeError: ‘function‘ object has no attribute ‘register‘

AttributeError: ‘function’ object has no attribute ‘register’

译文:AttributeError: ‘function’对象没有属性’register’

写的蓝图,如下:

蓝图

运行app.py

报错:

在这里插入图片描述

解决:

  1. 首先检查代码是否有问题
    1. 视图函数是否重名
    2. 创建蓝图是名字是否一致
    from flask import Blueprint, render_template, redirect
    home = Blueprint("home", __name__)
    @home.route('/home')
    def indexHome():
    return render_template('index.html')
    

2.代码没问题,改变注册位置(我这样做报错解决)
1. 把注册代码放在app = Flask(name, template_folder=‘Templates’, static_url_path=‘/’, static_folder=‘static’)

   	from flask import Flask, render_template, Blueprint
from controller.home import *
from controller.prjoect import *
from controller.administration import *
from controller.system import *
app = Flask(__name__, template_folder='Templates', static_url_path='/', static_folder='static')
app.register_blueprint(home)
app.register_blueprint(project)
app.register_blueprint(administration)
app.register_blueprint(system)
@app.route('/user/password')
def updatePwd():
   return render_template('u_password.html')


if __name__ == '__main__':
   app.run()

完结撒花!!!

猜你喜欢

转载自blog.csdn.net/qq_44774287/article/details/124817559