A
A
axelvagabund2015-06-10 15:40:13
Flask
axelvagabund, 2015-06-10 15:40:13

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

2 answer(s)
A
Andrey, 2015-06-10
@andreypaa

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'))

R
REDkiy, 2016-04-14
@REDkiy

Instead of: I would
do:
True, I don’t quite understand what the difference is. :-)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question