Created
May 9, 2014 12:57
-
-
Save steelywing/d984be442df831cdce11 to your computer and use it in GitHub Desktop.
flask regex route
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
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