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:
19
main.py
19
main.py
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user