AttributeError: ‘function’ object has no attribute ‘register’
译文:AttributeError: ‘function’对象没有属性’register’
写的蓝图,如下:
运行app.py
报错:
解决:
- 首先检查代码是否有问题
- 视图函数是否重名
- 创建蓝图是名字是否一致
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()