python 瓶子重定向导致错误 405:方法不允许

python bottle redirect resulting in Error 405 : Method not allowed

所以我一直在工作或一个快速的小项目,我遇到了这个问题

from bottle import get, post, request, run, redirect
import threading 

@get('/button')
def button():
    return '''
        <form action="/button" method="post">
            <input type="submit" value="Push"/>
        </form>
    '''
@post
def action():
    print ("button pushed")
    global pushed 
    pushed = True
    redirect("/button")


threading.Thread(target=run, kwargs=dict(host='localhost', port=80)).start()

pushed = False
print("Started")
while 1:

    if pushed:
        print("push recv")
        pushed = False

我 运行 我的代码使用 "sudo python3 code.py"

您还没有将路线附加到您的 @post 声明中。应该是:

@post('/button')