Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Does Flask support regular expressions in its URL routing

from flask import Flask
from werkzeug.routing import BaseConverter

app = Flask(__name__)

class RegexConverter(BaseConverter):
    def __init__(self, url_map, *items):
        super(RegexConverter, self).__init__(url_map)
        self.regex = items[0]


app.url_map.converters['regex'] = RegexConverter

@app.route('/<regex("[abcABC0-9]{4,6}"):uid>-<slug>/')
def example(uid, slug):
    return "uid: %s, slug: %s" % (uid, slug)


if __name__ == '__main__':
    app.run(debug=True, host='0.0.0.0', port=5000)
Comment

PREVIOUS NEXT
Code Example
Python :: how to set class attributes with kwargs python 
Python :: convert png rgba to rgb pyhton 
Python :: validating credit card numbers 
Python :: pyad create user 
Python :: where are docker logs 
Python :: python switch item 
Python :: what is in the python built in namespace 
Python :: python resample and interpolate 
Python :: 2d array python 
Python :: get raster corners python 
Python :: hello world in python 3 
Python :: Sort for Linked Lists python 
Python :: plotting mean in density plot ggplot2 
Python :: python append 
Python :: python remove first element of array 
Python :: root = tk() python 3 
Python :: read csv in spark 
Python :: python calculate the power of number 
Python :: mean bias error 
Python :: SystemError: error return without exception set 
Python :: pyspark groupby with condition 
Python :: que es una funcion en python 
Python :: dict python 
Python :: open python not write file 
Python :: Reversing Ints 
Python :: Fastest way to Convert Integers to Strings in Pandas DataFrame 
Python :: import excel 
Python :: private attributes python 
Python :: round float python 
Python :: |= operator python 
ADD CONTENT
Topic
Content
Source link
Name
3+9 =