猎鹰python中的数据传递应用

ksh*_*ngh 4 html python api falcon

在问这个问题之前,我想提一提,我知道我可以使用django代替该应用程序,但是我需要使用falcon而不是其他任何东西。

我只是在寻找一种方法

让我们采取一个非常简单的方案,以便我可以了解应用程序各个部分之间的数据流向。

我有一个使用html的简单登录页面:

<!DOCTYPE html>
<html>
<body>

<form action="***what-do-i-put-here***">
  <fieldset>
    <legend>Personal information:</legend>
    First name:<br>
    <input type="text" name="firstname" value="Mickey">
    <br>
    Last name:<br>
    <input type="text" name="lastname" value="Mouse">
    <br><br>
    <input type="submit" value="Submit">
  </fieldset>
</form>

</body>
</html>
Run Code Online (Sandbox Code Playgroud)

我使用默认存在于python中的simpleHTTpServer运行它。

现在,我只用一个响应者“ on_post()”创建了一个非常基本的猎鹰应用程序,该响应器仅使用从表单中接收到的数据进行回复,

我在localserver上使用uWsgi托管我的falcon应用程序。我如何使这两个不同的代码段彼此交互,以html形式表示,我们是如何在Php的情况下在“ actions”标签下定义php文件的名称的。鹘。

一个非常简单和小的工作示例受到高度赞赏

Pra*_*ain 6

这是一个有效的例子!

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <form action="http://127.0.0.1:8000" method="post">
        <input type="text" name="name">
        <button type="submit" name="btn">Submit</button>
    </form>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

猎鹰代码:

import falcon
from wsgiref import simple_server

class Resource(object):
    def on_post(self, req, resp):
        resp.status = falcon.HTTP_200
        resp.body = req.params['name']

app = api = falcon.API()
app.req_options.auto_parse_form_urlencoded = True
api.add_route('/', Resource())

if __name__ == '__main__':
    http = simple_server.make_server('127.0.0.1', 8000, app)
    http.serve_forever()
Run Code Online (Sandbox Code Playgroud)

  • 哇,我花了我一整天才找到“ api.req_options.auto_parse_form_urlencoded = True”。谢谢。 (2认同)