def new(): # Create the form form = EntryForm(request.form) # If we're posting and the form is filled out correctly # Create the new entry # Otherwise return the empty form if request.method == 'POST' and form.validate(): Entry.create(**form.data) return redirect('/') return render_template('new.html', form=form)
def edit(id): # Get selected entry and create the form entry = Entry.get(Entry.id == id) form = EntryForm(request.form, entry) # If we're posting and the form is filled out correctly # Update the entry # Otherwise render the empty form if request.method == 'POST' and form.validate(): print(form.data) Entry.update(**form.data).where(Entry.id == id).execute() return redirect('/') return render_template('edit.html', entry=entry, form=form)