def add_book(): if not session.get("logged"): abort(401) form = form_handler.AddBookForm(request.form) authors = db_handler.get_all_authors() form.choose_authors.choices = [(g.id, g.name) for g in authors] if request.method == "POST" and form.validate(): db_handler.add_book(form.title.data, form.choose_authors.data) flash("New book save successfully") return redirect(url_for('index')) else: for field in form: for error in field.errors: flash(error) return render_template("add_book.html", form=form)