Answer the question
In order to leave comments, you need to log in
How to delete posts (flask)?
Hello, I recently found a tutorial on creating a blog on flask. Before that, I didn’t deal with the back-end at all (I just played a little with django, and wrote something like a ToDo list, but I had already forgotten everything).
Tell me how to delete posts and comments in this very blog. And how can you replace slug with id-shniks (it's banal that there should be a number for the slug's place in the url, i.e. id)?
The blog'a code itself (github)
Answer the question
In order to leave comments, you need to log in
Here I took a code example from my project, I don’t pretend to be super accurate, but everything seems to be working fine.
Accordingly, some things will have to be replaced, but in general I think it is clear how to do it.
@blueprint.route("/event/delete/<int:event_id>", methods=['GET'])
@login_required
def event_del(event_id):
event = Event.query.filter_by(id=event_id, user_id=current_user.id).first()
if event:
event.delete()
flash("Event is deleted", 'success')
else:
flash("Event can not deleted", 'error')
return redirect(url_for('events_list'))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question