【问题标题】:Retrieving table field using web2py使用 web2py 检索表字段
【发布时间】:2013-08-02 15:49:32
【问题描述】:

我是 web2py 的新手。 我有一个表(表单),并且在我的 python 脚本中我想使用特定的字段值。

  def GetData()
       return request.vars.values()

此函数将所有字段一起提供给我,但我想知道如何从我的表单中获取“input1”(例如)字段的值。

表格:

 <form action="GetData" enctype="multipart/form-data" id="formId" method="post" 
 name="formId"> 
     <table>
        <tr id="field1">
          <input id="input1" name="input1" type="text" value="" />
        </tr>

        <tr id="field2">  
          <input id="input2" name="input2" type="text" value="" />
        </tr>

        <tr id="field3">
          <input type="submit" value="Submit" />
         </tr>
     </table>
  </form>

谢谢!!!

【问题讨论】:

  • request.vars["your_field"]

标签: python web2py


【解决方案1】:

来自web2pybook

请求对象是无处不在的 web2py 类的实例,称为 gluon.storage.Storage,它扩展了 Python dict 类。它基本上是一个字典,但项目值也可以作为属性访问:

这就是你需要的。

p = request.vars['p'] 
q = request.vars['q'] 

【讨论】:

  • 知道了。太感谢了。问题是我使用的是 id 而不是名称标签。 :)
【解决方案2】:
input1 = request.vars.input1
etc.

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-21
    • 1970-01-01
    • 2014-06-05
    • 1970-01-01
    • 1970-01-01
    • 2011-09-01
    • 2015-10-14
    相关资源
    最近更新 更多