Skip to content

Instantly share code, notes, and snippets.

@steelywing
Created May 9, 2014 12:57
Show Gist options
  • Save steelywing/d984be442df831cdce11 to your computer and use it in GitHub Desktop.
Save steelywing/d984be442df831cdce11 to your computer and use it in GitHub Desktop.
flask regex route
from flask import Flask
from werkzeug.routing import BaseConverter
app = Flask(__name__)
class RegExConverter(BaseConverter):
def __init__(self, map, regex='[^/]+'):
super().__init__(map)
self.regex = regex
app.url_map.converters['regex'] = RegExConverter
@app.route('/<regex("[0-9a-f]+"):hex>/')
def example(hex):
return "hex: %s" % hex
if __name__ == '__main__':
app.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment