Skip to content

Instantly share code, notes, and snippets.

@fhats
fhats / flask_routes_in_doc
Created December 11, 2011 03:26
Subclass of Flask to automatically store routes in the view handler's docstrings
class FlaskWithRouteDocs(Flask):
"""A subclass of Flask to allow using :route: and :methods: in docstrings, a la Sphinx."""
def route(self, rule, **options):
def decorator(f):
route_dec = super(FlaskWithRouteDocs, self).route(rule, **options)
methods_str = ','.join(options.get('methods', ['GET']))
if f.__doc__ is not None and ":route:" in f.__doc__:
f.__doc__ = f.__doc__.replace(":route:", rule)
else: