V
V
Vlad2019-09-04 22:05:44
Flask
Vlad, 2019-09-04 22:05:44

Why is the post edit form not working in flask?

Good afternoon! I use the form.populate_obj(post) method. but after editing the post, I will be redirected again to the form for editing this post, but which remained unchanged
Here is the code of the function that should edit the post.

@posts.route('/<slug>/edit/', methods = ['POST', 'GET'])
def edit_post(slug):
    post = Post.query.filter(Post.slug ==slug).first()

    if request.method ==' POST' :
        form = PostForm(formdata=request.form, obj =post)
        form.populate_obj(post)
        db.session.add(post)
        db.session.commit()
        return redirect(url_for('posts.post_detail', slug = post.slug, ))

    form = PostForm(obj=post)
    return render_template('posts/edit.html', post=post, form = form)

Please tell me why my post editing is not working.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question