Bottle - GETパラメータとPOSTデータをまとめて送受信する

from bottle import get, post, request, run

@get('/form')
def func():
    return '''
        <form action="?foo=bar" method="post">
            <input type="hidden" name="hoge" value="fuga">
            <input value="submit" type="submit">
        </form>
    '''

@post('/form')
def func():
    print(request.query.get('foo')) #GET
    print(request.forms.get('hoge')) #POST

run(host='localhost', port=8080)

サーバを起動しlocalhost:8080/formにアクセスして送信。

127.0.0.1 - - [13/Apr/2021 20:51:09] "GET /form HTTP/1.1" 200 176
bar
fuga
127.0.0.1 - - [13/Apr/2021 20:51:11] "POST /form?foo=bar HTTP/1.1" 200 0

参考