Skip to content

Instantly share code, notes, and snippets.

@geoffalday
Created January 29, 2012 05:04
Show Gist options
  • Save geoffalday/1697296 to your computer and use it in GitHub Desktop.
Save geoffalday/1697296 to your computer and use it in GitHub Desktop.
Two Methods per Alex
@app.route('/edit/<int:page_id>', methods=['GET'])
def edit(page_id):
context = "Edit"
page = Page.query.get(page_id)
title = page.title
text = page.text
return render_template('edit.html', title=title, text=text, context=context)
@app.route('/edit/<int:page_id>', methods=['POST'])
def update(page_id):
context = "Edit"
title = request.form['title']
text = request.form['text']
if not request.form['title']:
flash('Title is required', 'error')
elif not request.form['text']:
flash('Text is required', 'error')
else:
page = Page.query.get(page_id)
page.title = title
page.text = text
db.session.commit()
flash(u'Page was successfully updated')
return redirect(url_for('show_all'))
return render_template('edit.html', title=title, text=text, context=context)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment