Browse Source

删除功能

fudan
欧醚 4 years ago
parent
commit
60df9c47bf
Signed by: OmmyZhang GPG Key ID: 757D312E7C9D13F7
2 changed files with 22 additions and 0 deletions
  1. +14
    -0
      app.py
  2. +8
    -0
      templates/list.html

+ 14
- 0
app.py View File

@ -133,6 +133,20 @@ def like(id):
return str(c.likeNum) return str(c.likeNum)
@app.route('/ordinary/<int:id>/delete', methods=['POST'])
def delete(id):
key = request.form.get('key')
if key != C.key:
abort(401)
c = Candidate.query.get(id)
if not c:
abort(404)
db.session.delete(c)
db.session.commit()
return redirect('..')
if __name__ == '__main__': if __name__ == '__main__':
app.run(debug=True) app.run(debug=True)

+ 8
- 0
templates/list.html View File

@ -240,6 +240,14 @@
</div> </div>
{% for c in pagination.items %} {% for c in pagination.items %}
<div class="qbox"> <div class="qbox">
{% if showPrivate %}
<form action="{{c.id}}/delete" method="post">
<input type="hidden" name="key" value="{{key}}">
<button type="submit" class="close" aria-label="Close">
<span>×</span>
</button>
</form>
{% endif %}
<small>No. {{c.id}}</small> <small>No. {{c.id}}</small>
<pre class="inner">{{c.content}}</pre> <pre class="inner">{{c.content}}</pre>
{% if showPrivate %} {% if showPrivate %}

Loading…
Cancel
Save