Blog post is not getting Edited in flask

Viewed 21

There are no errors, but when i press edit and make changes it doesnt work. below is my code for both html and python flask

#python code

@app.route('/posts/edit/<int:id>', methods=['GET', 'POST'])

def edit(id):

    post = BlogPost.query.get_or_404(id)

    if request.method== 'POST':
        
        post_title=request.form['title']
        post_content=request.form['content']
        post_author=request.form['author']
        db.session.commit()
        return redirect('/posts') 
    else:
        return render_template('edit.html', post=post)

#html code
<h1> Edit Blog Post</h1>
<hr>
<h2>Edit Post :</h2>
<form action ='/posts/edit/{{post.id}}' method ='POST'>
    Title: <input type ='text' name ='title' id ='title' value="{{post.title}}">
    <br>
    Post:<input type ='text' name='content' id ='content' value="{{post.content}}">
    <br>
    Author:<input type = 'text' name = 'author' id = 'author' value ="{{post.author}}">
    <br>

    <input type='submit' value ="Save">
</form>
<hr>
{% endblock %}

this shows no error but when i hit save button it redirects me back to post page without any changes

0 Answers
Related