我有两个HTML按钮。一个用于启动任务,另一个用于停止任务:
开始时间:
<form action="localhost:5000/data" method="POST">
<input type="submit" name="Start Data Collection" value="Start Data Collection"/>
</form>
停止:
^{pr2}$我正在使用flask来构建我的web服务器。处理启动按钮的烧瓶代码是:
@app.route('/data', methods=['POST'])
def recvdata():
message = {"message":"start_socket"}
messageQueue.put(message)
return redirect("/")
停下来:
@app.route('/stop', methods=['POST'])
def stop_task():
message = {'message':'stop'}
messageQueue.put(message)
return redirect("/")
这两个按钮都是为了在处理后重定向回主页。启动按钮没有问题。停止按钮重定向到localhost:5000/localhost:5000/stop
,我似乎不明白为什么。我做错什么了?在
无论何时确定链接,如果该链接不是以协议或
//
开头的,它将被附加到当前路径。在因此,与其
action="localhost:5000/stop"
,不如将其设置为action="//localhost:5000/stop"
,强制它使用您现在使用的相同协议(http或https)。在对
action="localhost:5000/data"
也应该这样做,变成action="//localhost:5000/data"
相关问题 更多 >
编程相关推荐