【问题标题】:Passing argument to python handler将参数传递给 python 处理程序
【发布时间】:2015-07-14 23:19:55
【问题描述】:

我通过表值中的链接调用处理程序,如下所示:

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

处理程序有一个我想根据单元格的 ID 或值运行的 SQL 查询,因此当单击链接时,它会发送唯一的名称。我试图阅读有关 URI 路由的 webapp2 文档,但不明白如何将其应用于我的问题。

【问题讨论】:

  • 我在创建处理程序路由时使用它:('/regex/(\d+)', Handler),但是当我在我的 href 链接中调用它时,它会选择测试 ['test_name' ] 在网址中
  • 如何从我的 href 中正确调用它?我有它作为 href = "/regex/{{ test['test_name'] }}"

标签: python google-app-engine handler webapp2


【解决方案1】:

URI Routing 的文档中,示例显示:

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

对于您的处理程序,您可以使用:

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

然后你会调用它:

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

id="..." 属性不作为 URL 的一部分传递,它是一个 HTML 属性。)

注意:您可能需要对参数 test['test_name'] 进行 URL 编码。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-01-14
    • 2012-08-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-14
    相关资源
    最近更新 更多