1

I defined a blueprint route like this:

@mod_patient_directory.route('/delete-patient/<string:doc_id>',  methods = ['GET'])
def delete_record(self, doc_id):
    mongo.db.patient.remove({'_id': doc_id})
    return redirect(url_for('main-page'))

And on the form I called the method that is:

 <form action="{{ url_for('patient_directory.delete_record',doc_id= doc_id )}}" method="post">
                              <input type="hidden" name="docId" id="docId" value="{{ patient_doc._id }}" />
                              <input type="hidden" name="action" id="action" value="delete" />
                              <button type="submit" class="btn btn-default btn-sm">
                                  <span class="glyphicon glyphicon-remove"></span>
                              </button>
 </form>

Can anybody tell me why I'm getting a 404 error?

4

1 回答 1

0

一个问题是您methods = ['GET']在路线上,但method="post"在表单标签上。您不应该将GET其用于删除记录等危险操作,因此您应该将methods接受更改为['POST'].

正如@Makoto 指出的那样,这会给你一个 405 错误,但是你得到一个 404 错误,所以肯定还有另一个问题。您已经发布了如何注册蓝图,但是您在代码中的哪个位置执行此操作?使用蓝图要注意的一件事是,您需要在注册蓝图之前注册所有路线。

于 2015-03-22T23:42:59.980 回答