Blog Capstone Project Part 3 - RESTful Routing
Goal: Getting api to retrieving from database
Turn on debug mode to find out the problem
if __name__ == "__main__": app.run(debug=True) #app.run(host='0.0.0.0', port=5000)
-> problem was about non-existing keyword_argument on route
-> start with debug=True, to figure out the error
db.session.query(BlogPost).all()
book_id = 1
db.session.query(Book).get(book_id)
When href got a route that doesn't exist yet, it will cause error. Simply put dummy route to quiet it for now.
post.html
<a class="btn"
href="{{url_for('edit_post',post_id=post.id)}}">Edit Post</a>
main.py
@app.route("/edit_post")
def edit_post():
pass
You need to pass your object to the form when you create it.
edit_form = CreatePostForm( title=post.title...)```
@app.route("/edit-post/<post_id>", methods=["GET","POST"])
def edit_post(post_id):
edit_post = db.session.query(BlogPost).get(post_id)
edit_form = CreatePostForm(
title=post.title,
subtitle=post.subtitle,
img_url=post.img_url,
author=post.author,
body=post.body
)
return render_template("make-post.html", edit_form=edit_form, is_edit=True)
@app.route("/new-post", methods=["GET","POST"])
def new_post():
new_form = CreatePostForm()
return render_template("make-post.html", new_form=new_form, is_edit=False)
{% if is_edit: %}
{{ wtf.quick_form(edit_form) }}
{% else: %}
{{ wtf.quick_form(new_form) }}
{% endif %}
{{ ckeditor.load() }}
{{ ckeditor.config(name='body') }}