updated README to reflect next steps (will use flask-wtf and flask-boostrap), but proof-of-concept author/<id> works to save to database with a form / POST

This commit is contained in:
2020-11-11 19:23:48 +11:00
parent f7ea6870d2
commit a4dca1dbf5
4 changed files with 62 additions and 12 deletions

19
main.py
View File

@@ -167,9 +167,24 @@ def book(id):
return render_template("books.html", books=book_s, subs=sub_book )
@app.route("/authors", methods=["GET"])
def author():
def authors():
authors = Author.query.all()
return render_template("author.html", authors=authors)
return render_template("authors.html", authors=authors)
@app.route("/author/<id>", methods=["GET", "POST"])
def author(id):
if request.method == 'POST':
id = request.form['author.id']
author = Author.query.get(id)
author.firstnames = request.form['author.firstnames']
author.surname = request.form['author.surname']
db.session.commit()
message="Successfully Updated Author (id={})".format(id)
else:
author = Author.query.get(id)
message=""
return render_template("author.html", author=author, message=message)
if __name__ == "__main__":
app.run(host="0.0.0.0", debug=True)