简体   繁体   English

将参数传递给python处理程序

[英]Passing argument to python handler

I am calling on a handler through a link in a table value , like this: 我正在通过表值中的链接调用处理程序,如下所示:

<td><a id="{{ test['test_name'] }}" href="/regex" >{{ test['test_name'] }}</a></td>

The handler has a SQL query that I want to run based on the id, or value of the cell, so when the link is clicked it send the unique name. 该处理程序具有一个我想根据ID或单元格的值运行的SQL查询,因此当单击链接时,它将发送唯一的名称。 I tried to read webapp2 documentation on URI routing but couldn't understand how to apply it to my problem. 我尝试阅读有关URI路由的webapp2文档,但不明白如何将其应用于我的问题。

In the documentation on URI Routing , the example shows: 在有关URI路由的文档中,该示例显示:

app = webapp2.WSGIApplication([
    (r'/', HomeHandler),
    (r'/products', ProductListHandler),
    (r'/products/(\d+)', ProductHandler),
])

For your handler, you could use: 对于您的处理程序,您可以使用:

app = webapp2.WSGIApplication([
    (r'/regex/<test>', RegexHandler),
])

Then you would call it using: 然后,您可以使用以下命令调用它:

<a href="/regex/{{ test['test_name'] }}" >{{ test['test_name'] }}</a>

(The id="..." attribute is not passed as part of the URL, it's an HTML attribute.) id="..."属性未作为URL的一部分传递,它是HTML属性。)

Note: you may need to URL-encode the parameter test['test_name'] . 注意:您可能需要对参数test['test_name']进行URL编码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM