Skip to content

Instantly share code, notes, and snippets.

@nomeyer
Created February 12, 2016 15:06
Show Gist options
  • Save nomeyer/b86dacd9c00bd750087a to your computer and use it in GitHub Desktop.
Save nomeyer/b86dacd9c00bd750087a to your computer and use it in GitHub Desktop.
Flask catchall endpoint for optional path parameter
@app.route('/', methods=['GET'], defaults={'var': 'default'})
@app.route('/<string:var>', methods=['GET'])
def page(var):
# do stuff with the given var or default
return render_template('page.html', var=var)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment