Created
January 29, 2012 05:04
-
-
Save geoffalday/1697296 to your computer and use it in GitHub Desktop.
Two Methods per Alex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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