为了账号安全,请及时绑定邮箱和手机立即绑定

为什么 Flask 中的错误“AttributeError: 'NoneType' object ”

为什么 Flask 中的错误“AttributeError: 'NoneType' object ”

繁花如伊 2023-03-16 15:31:30
构建 Flask 应用程序,并尝试按日期/流行度更改条目/卡片的选择。我被困在这里是因为这个错误不是恒定的,它偶尔会触发。我希望我能让这个排序功能正常工作,然后看看这个问题,我认为这只是一个小错误。但是,现在错误更频繁地触发,我担心我只是在这种方法上浪费了我的时间;但我不知道。App.pydef tester(page):    limit = 6    offset = (int(page) - 1) * limit    requested = request.args.get('fromHTMLchoice')    print(requested)    requestChoice = requested.split()    a = requestChoice[0]    b = requestChoice[1]    convertChoice = tuple(a[2:-2], int(b[:-1]))    sagas_pages = sagas.find().sort(                        [convertChoice]).skip(offset).limit(limit)    return render_template(                "tester.html",                sagas_pages=sagas_pages, page=page                      )HTML<form class="form-inline" method="GET" action="{{url_for('tester', page=1)}}">            <div class="form-group">                <div class="input-group">                    <span class="input-group-addon">Please select</span>                        <select name="fromHTMLchoice" class="selectpicker form-control">                            <option value= "('totalLikes', -1)">Likes</option>                            <option value= "('totalLikes', 1)">Dislikes</option>                            <option value= "('_id', -1)">Most_Recent</option>                            <option value= "('_id', 1)">Least_Recent</option>                        </select>                </div>                <button type="submit" class="btn btn-default">Go</button>            </div>        </form>
查看完整描述

1 回答

?
繁华开满天机

TA贡献1816条经验 获得超4个赞

该 AttributeError 是问题的下游。要调试的问题是为什么

requested = request.args.get('fromHTMLchoice')
print(requested)

某人打印None,就像日志顶部一样。安全的赌注是,不知何故,tester通过没有fromHTMLChoice参数的 URL 被调用。


查看完整回答
反对 回复 2023-03-16
  • 1 回答
  • 0 关注
  • 64 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信