def create_author(): af = AuthorForm() if af.author_form_submit.data and af.validate_on_submit(): author = Author() author.name = af.name.data author.biography = af.biography.data db.session.add(author) db.session.commit() # fields return render_template('create_author.html', af=af)
def create_author(): form = AuthorForm() if form.validate_on_submit(): new_author = Author(name=form.name.data, biography=form.biography.data) db.session.add(new_author) db.session.commit() flash("New Author was created succesfully.") return redirect("/") return render_template('create_author.html', form=form)
def create_author(): form = AuthorForm() if form.validate_on_submit(): new_author = Author( name=form.name.data, biography=form.biography.data, dob=form.dob.data, country=form.country.data, ) db.session.add(new_author) db.session.commit() flash("New author was created successfully.") return redirect(url_for("main.homepage")) return render_template("create_author.html", form=form)
def create_author(): # TODO: Make an AuthorForm instance form = AuthorForm() # TODO: If the form was submitted and is valid, create a new Author object # and save to the database, then flash a success message to the user and # redirect to the homepage if form.validate_on_submit(): new_author = Author(name=form.name.data, biography=form.biography.data) db.session.add(new_author) db.session.commit() # TODO: Send the form object to the template, and use it to render the form # fields return render_template('create_author.html', form=form)
def create_author(): form = AuthorForm() # if form was submitted and contained no errors if form.validate_on_submit(): new_author = Author( name = form.name.data, biography = form.biography.data, birth_date = form.birth_date.data, country = form.country.data, ) db.session.add(new_author) db.session.commit() flash('New author was created successfully.') return redirect(url_for('main.homepage')) return render_template('create_author.html', form=form)