标签:使用 try 返回 rgs constant ted user unbound app
报错: UnboundLocalError: local variable ‘total_page‘ referenced before assignment
news_list = []
# 修改
total_page =1
current_page = 1
try: paginate = user.collection_news.paginate(page, constants, USER_COLLECTION_MAX_NEWS, False) current_page = paginate.page total_page = paginate.pages news_list = paginate.items except Exception as e: current_app.logger.error(e) news_dict_li = [] for news in news_list: news_dict_li.append(news.to_dict()) data = { "total_page": total_page, "current_page": current_page, "collections": news_dict_li }
报错: 使用前 未定义 total_page
原因: 赋值 current_page和 total_page 在try中,如果失败将不会赋值 所以提前在代码前定义变量 total_page = 1 current_page = 1 可以解决报错
报错:ERROR in views [C:\Users\93263\myproject\information27\info\modules\profile\views.py:33]:
‘AppenderBaseQuery‘ object has no attribute ‘pagnate‘
报错: 没有对象pagnae
原因: 在view 33行 返回的错误日志,未找到对象方法pagnate
报错:‘<‘ not supported between instances of ‘bool‘ and ‘module‘
ERROR:info:‘<‘ not supported between instances of ‘str‘ and ‘int‘
原: page = request.args.get("p", 1) 修改: page = request.args.get("p", 1) page = int(page)
原:
paginate = user.collection_news.paginate(page, constants,USER_COLLECTION_MAX_NEWS, False)
修改:paginate = user.collection_news.paginate(page, constants.USER_COLLECTION_MAX_NEWS, False)
报错: 参数不支持 bool类型和module类型进行比较 、 不支持str类型和 int类型进行比较
原因: 调用方法时候 输入参数错误
标签:使用 try 返回 rgs constant ted user unbound app
原文地址:https://www.cnblogs.com/oscarli/p/12302162.html