Answer the question
In order to leave comments, you need to log in
Why doesn't post editing work?
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)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question