mattupstate / overholt

Example Flask application illustrating some of my common practices
http://mattupstate.com/blog/how-i-structure-my-flask-applications/
MIT License
1.6k stars 236 forks source link

How to use more then one route on the same view function? #21

Closed kinorsi closed 10 years ago

kinorsi commented 10 years ago

Currently, a view function only has one route. @route(bp, '/someurl', methods=['GET']). e.g. But how about if I need more then one url mapping for the same view function?

kinorsi commented 10 years ago

My current solution:

------------------------------

def route(bp, *args, **kwargs):
    def decorator(f):
        @wraps(f)
        def wrapper(*args, **kwargs):
            return f(*args, **kwargs)
        fun = wrapper
        for arg in args:
            fun = bp.route(arg, **kwargs)(fun)
        return fun
    return decorator