在routes.py
中,我有一个函数:
@app.route('/')
@app.route('/makecsc_relocation')
def makecsc_relocation(csc_post_index):
...
makeCscRelocationRep(repname, csc_post_index)
return send_file(repname+'.xlsx', as_attachment=True, attachment_filename=repname+' '+csc_post_index+'.xlsx')
在index
中,我有以下内容:
如果我使用的函数在<form action="">
中没有参数,并向它传递一个空的input
值,一切都正常,但是当我试图将input post_index
作为该函数的参数时,我得到了内部服务器错误,其URL如下:
http://myservername/makecsc_relocation?post_index=452680
我怎么解决这个问题?在
函数参数总是路径参数,即注册到
@app.route()
的路由路径中的<parametername>
组件。你没有这样的参数,所以不要给你的函数任何参数。请参阅烧瓶快速启动中的Variable Rules。在查询参数(表单中的key=value对,放在URL中的} 结束:
?
之后)以^{请参阅快速入门的The Request Object部分。在
request.args.get(...)
。在request.args[...]
。如果缺少查询参数,则会向客户端提供400个错误请求HTTP错误响应。在有关此映射如何工作的详细信息,请参见Werkzeug ^{} documentation 。在
最后我得出了以下解决方案:
POST
方法- 在函数
^{pr2}$makecsc_relocation
中,我添加了以下字符串:并将其传递给
makeCscRelocationRep
相关问题 更多 >
编程相关推荐