执行Flask程序时,时常报AttributeError: 'function' object has no attribute 'name'

写Python程序时,有时会报AttributeError: 'function' object has no attribute 'name'错误,仔细检查了程序,发现代码并没有错误,例如我写的程序:

# coding:utf8
from flask import Blueprint, Flask

pro = Blueprint('blue', __name__)

@pro.route('/pro')
def pro():

    return 'pro'

在注册时,总是报这个错,检查了好几遍也没发现代码本身有什么错误

执行Flask程序时,时常报AttributeError: 'function' object has no attribute 'name'

后来将代码修改成如下便不再报错:

# coding:utf8
from flask import Blueprint, Flask

pro = Blueprint('blue', __name__)

@pro.route('/pro')
def proo():

    return 'pro'

执行Flask程序时,时常报AttributeError: 'function' object has no attribute 'name'

所以,出现AttributeError: 'function' object has no attribute 'name'错误时,并不一定是你的代码有问题,而是使用的变量名可能与系统(包括扩展库或者保留字...)的重复了,修改变量名之后就可以了。当然,这是在你排除了代码本身没有错误的情况之后,可能的原因之一。