2017-06-28 58 views
0

我想写一个简单的瓶应用程序,我使用Postgresql作为数据库。我试图更新按钮,单击表行,但它给我下面的错误sqlalchemy.exc.DataError在Postgresql执行更新查询

DataError: (psycopg2.DataError) invalid input syntax for integer: "125/" LINE 1: ...ATE tasks SET taskname='IamUpdated' WHERE tasks.uid = '125/'^[SQL: 'UPDATE tasks SET taskname=%(taskname)s WHERE tasks.uid = %(uid_1)s'] [parameters: {'taskname': 'IamUpdated', 'uid_1': u'125/'}]

我不知道这是否是加入“/”结尾的毛刺或者它应该是这样的?或者那是造成错误的原因。 请帮助。

以下是我的瓶Python代码

edituser = request.form.getlist('editId') 
     if edituser: 
      for e in edituser: 
       User.query.filter_by(uid=e).update(dict(taskname="IamUpdated")) 
      db.session.commit() 
      return render_template("index.html",User=User.query.all()) 

以下是我的HTML代码

<form action="" method="POST"> 

    <div ng-controller="myctrl" > 

    <table> 
     <caption> Todo List</caption> 
      <thead> 
       <tr> 
        <td> 
         <input type="text" name="text"> 
         <input type="submit" value="Add Task" > 

        </td><td> 
        Search :<input type="text"> 

        </td> 
       </tr> 
       <tr> 
        <th>Task Id</th> 
        <th>Task</th> 
       </tr> 
      </thead> 

      <tbody> 

       {% for user in User %} 
       <tr> 
        <td> {{ user.uid }} </td> 
        <td >{{ user.taskname }} 
         <input type="image" class="deleteImg" src="static/img/trash_can.png" height="15px" width="18px" name="removeId" value={{user.uid}} /> 
         <input type="image" src="static/img/editbtn.svg" height="15px" width="18px" name="editId" value={{user.uid}}/> 

        </td> 
       </tr> 
       {% endfor %} 
      </tbody> 
     </table> 
    </div> 

    <script> 

    var app = angular.module("app", ['xeditable']); 
    app.controller('myctrl', function($scope) { 
    $scope.myname="Howdy";  
    }); 
    app.config(function($interpolateProvider) { 
     $interpolateProvider.startSymbol('//').endSymbol('//'); 
    }); 

    app.run(function(editableOptions) { 
     editableOptions.theme = 'bs3'; // bootstrap3 theme. Can be also 'bs2', 'default' 
    }); 
    </script> 
</form> 
</body> 

+0

我们需要看看editId来自哪里。我怀疑你的模板有错误。 – Shadow

+0

@shadow请检查我添加了HTML代码 – Prasanna

回答

1

您的问题似乎是这样的标签在这里:

<input type="image" src="static/img/editbtn.svg" height="15px" width="18px" name="editId" value={{user.uid}}/> 

在HTML中,所有值都是字符串。所以他们都必须被引用。

value="{{user.uid}}" 

一旦你完成了这一步,HTML就会准确地知道你想要包含在值中而不是猜测。

这并未影响其他字段的原因是因为这是您唯一没有在值和数字之间放置空格的时间。

0

错误是因为我在输入标记的末尾有“/>”。这是没有必要的。我已经删除它,现在它工作正常。

+0

这在技术上是可行的 - 但它没有解决您的真实问题 - 即不引用您的价值。请参阅我的答案了解更多详情。 – Shadow