猎鹰python中的数据传递应用 [英] data passing app in falcon python

查看:110
本文介绍了猎鹰python中的数据传递应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Before asking the question i want to mention that i am aware of the fact that i can use django instead to make the app, but i need to use falcon and nothing else.

我只是在寻找一种方法

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

lets take a very simple scenario so that i can understand how data flows between various parts of the app.

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

i have a simple login page using 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>

我使用python默认存在的simpleHTTpServer运行它.

i run it using simpleHTTpServer present by default in python.

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

now i create a very basic falcon app with just one responder "on_post()" which just replies back with the data that it recieved from the form,

我在localserver上使用uWsgi托管我的falcon应用程序.我如何使这两个不同的代码段相互交互,以html形式表示,我们在php情况下的工作是在"actions"标签下定义php文件的名称.猎鹰.

i am using uWsgi on localserver to host my falcon app. how do i the make these two different pieces of code to interact with each other i mean in the html form ,what we do in case of Php is we define the name of php file under "actions" tag .how do we do this in falcon.

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

a very simple and small working example is highly appreciated

推荐答案

这是一个可行的示例!

<!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>

猎鹰代码:

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()

这篇关于猎鹰python中的数据传递应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆