Skip to content

Instantly share code, notes, and snippets.

@sai-prasanna
Created August 12, 2013 05:53
Show Gist options
  • Save sai-prasanna/6208519 to your computer and use it in GitHub Desktop.
Save sai-prasanna/6208519 to your computer and use it in GitHub Desktop.
Redirect url to correct one when id is correct. Consider blog with /id/slug as url for a specific post if user enters /id/foo it must redirect to /id/slug
@app.route('/post/<id>')
@app.route('/post/<id>/<slug>')
def view_post(id, slug=None):
post = models.Post.query.get_or_404(id)
if post.slug != slug:
return redirect(url_for('post', id=id,slug = post.slug))
return render_template("post.html", post=post)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment