how to pass value from view to controller in web2py

谁说胖子不能爱 提交于 2019-12-04 06:37:05

问题


I want to insert the value of lang to mysql table. How to pass the value of lang to controller

view
<script type="text/javascript">
    function test(it)
    {
        var lang=it.value;
    }
</script>
<form>
<p>language
<select id="select"  onchange="test(this)">
  <option value ="0">c</option>
  <option value ="1">cc</option>
  <option value="2">pas</option>
  <option value="3">java</option>
  <option value ="4">rb</option>
</select>
</p>
</form>

conteoller
def problem(lang):
{
}

Thanks!


回答1:


web2py doesn't work quite like that. Before proceeding, I suggest you read some of the introductory documenation as well as the documentation on forms.

If you submit a form to a web2py URL, the function that handles that URL can access the form variables in request.vars (also, request.post_vars if submitted via POST and request.get_vars if submitted via GET). In the case of your code, you would need to add a "name" attribute with the value "lang" to the <select> element, in which case, the receiving action could access the value via request.vars.lang. You controller action itself should not take any arguments.

Instead, though, you might find it easier to use web2py's built in forms functionality as noted above.



来源:https://stackoverflow.com/questions/26041216/how-to-pass-value-from-view-to-controller-in-web2py

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!