我想使用表单将数据存储在数据库中。使用web2py中的表格插入数据到数据库中
我怎么能做到这一点,而无需使用SQLFORM
像php
我们使用$var = $_POST['var_form']
我创建了模件文件中的表名为Produit
db.define_table('Produit',`enter code here`
Field('Nom', requires = IS_NOT_EMPTY()),
Field('Poid', 'float', requires = IS_NOT_EMPTY()),
Field('Prix', 'float', requires = IS_NOT_EMPTY()),
Field('Expiration', 'datetime'),
auth.signature)
而创建的窗体像
{{extend 'layout.html'}}
<form action="create" method=post>
<fieldset>
<legend><h1><center><em>Ajouter un produit</em></center></h1></legend>
Nom:<br>
<input type="text" name="nom" required/>
<br>
Poid:<br>
<input type="text" name="poid" required/>
<br>
Prix:<br>
<input type="text" name="prix" required/>
<br>
Date d'expiration:<br>
<input type="date" name="exp" required/>
<br>
<br><br>
<input type="submit" value="Ajouter">
谢谢 但我有另一个问题 当我在数据库“产品”上插入产品时,我发现它,但我发现其他产品的值为'无'。 –
@ AmineSghiouriEl-idrissi这意味着你的控制器包含'insert'语句调用两次。您是否刷新了该控制器的视图或直接打开了上述控制器的视图。添加[pdb](http://stackoverflow.com/questions/4228637/getting-started-with-the-python-debugger-pdb)并检查。 –