文章内容
2023/5/24 10:14:27,作 者: 黄兵
AttributeError: 'function' object has no attribute 'route'
今天新增一个 Flask 中的蓝图,结果报如下错误:
AttributeError: 'function' object has no attribute 'route'
具体代码如下:
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
from flask import render_template, g
from . import product
from ..decorators import nmr_decorators
@product.route('/', methods=['GET'])
@nmr_decorators()
def product(product_name):
return render_template('products/products.html', name=g.title, description=g.description, keywords=g.keywords) 出现问题的原因:
发生在路由名称和函数名称相同时就会出现上面的一个错误。
这似乎是 Flask 中的一个错误。
解决方案:
修改 product() 函数名:
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
from flask import render_template, g
from . import product
from ..decorators import nmr_decorators
@product.route('/', methods=['GET'])
@nmr_decorators()
def get_product(product_name):
return render_template('products/products.html', name=g.title, description=g.description, keywords=g.keywords) 参考资料:
1、Registering route on blueprint raises AttributeError: 'function' object has no attribute 'route'
其它相关推荐:
4、Flask Bootstrap 使用CDN减轻服务器压力 flask网站优化
黄兵个人博客原创。
转载请注明出处:黄兵个人博客 - AttributeError: 'function' object has no attribute 'route'
MySQL - 如何修复 Incorrect string value 错误
Top 10 Free Sites to Receive SMS Online Without Real Phone Number
Top 10 Free Sites to Receive SMS Online Without Real Phone Number
评论列表