2017-10-06 69 views
0

我有一个带有HTML <select>标记的Odoo模块,并且我想将<option>值(在选择标记内)传递给Python模型,并使用此值做一些事情。 有人可以指导我吗?Odoo 10:如何将html元素值传递给Python

XML代码:

<form> 
    <select style="width: 200px" id="dropdown"> 
      <option value="volvo">Value1</option> 
      <option value="saab">Value2</option> 
    </select> 
</form> 

我的一些Python代码我想:

 @http.route('/my_module/',auth='public') 
     def get_ip_address(self,**kw): 
      values = http.request.env['my_module.name'] 
      print values 

回答

0

你必须写在表单中选择选项,并在表单动作你会得到选择值。如果你更新代码的问题,我们可以帮你

<form action="/xxxxx" method="POST" id="unique_id"> 
<select style="width: 200px" id="dropdown"> 
     <option value="volvo">Value1</option> 
     <option value="saab">Value2</option> 
</select> 
</form> 

在HTTP控制器

@http.route(['/xxxx'], type='http', website=True, auth='public') 
def func(self,**post): 
    print post, "Here Check post values" 

工作实例测试:

      <form method="post" action="/website_payment/delete/"> 
          <input type="hidden" name="csrf_token" t-att-value="request.csrf_token()"/> 
          <div class="form-group"> 
           <select name="delete_pm_id" class="form-control" > 
            <t t-foreach="pms" t-as="pm"> 
             <option t-att-value="pm.id" t-esc="pm.name"/> 
            </t> 
           </select> 
          </div> 
          <div class="clearfix"></div> 
          <button class="btn btn-primary">Delete <span class="fa fa-long-arrow-right"></span></button> 
         </form> 


@http.route(['/website_payment/delete/'], methods=['POST'], type='http', auth="user", website=True) 
def delete(self, delete_pm_id=None): 
    if delete_pm_id: 
     pay_meth = request.env['payment.method'].browse(int(delete_pm_id)) 
     pay_meth.unlink() 
    return request.redirect('/my/payment_method') 
+0

我只是用Xml代码更新我的问题,因为在Python中我不知道如何从这个Xml中获取选项值。我在其他网页上阅读,http.request可能是必要的,但我很困惑。 – SirGuacamole

+0

不起作用,当我运行该函数时,我得到以下输出:{}这里检查帖子值,但不是在下拉列表中选择的选项值(选择标签) – SirGuacamole

+0

给名称选择字段 –

0

你所寻找的是HTML和CSS。

<span style="color:red"><b>This is red</b></span> 

使用template来制作页面。

相关问题