Created
August 12, 2013 05:53
-
-
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
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('/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