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

查看:41
本文介绍了猎鹰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.

现在我创建了一个非常基本的 falcon 应用程序,只有一个响应者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,

我在本地服务器上使用 uWsgi 来托管我的猎鹰应用程序.我如何使这两个不同的代码段相互交互我的意思是在 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天全站免登陆