Created
September 28, 2018 11:11
-
-
Save mei-li/bb712fb8d8287bc54f4969fbd58eb658 to your computer and use it in GitHub Desktop.
Getting all the routes and methods for a Pyramid 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 pyramid.interfaces import IRoutesMapper | |
from pyramid.config.predicates import RequestMethodPredicate | |
mapper = request.registry.queryUtility(IRoutesMapper) | |
json_routes = [] | |
for route in mapper.get_routes(): | |
if 'json' not in route.name: # custom convention: Only routes with json in the name as interesting | |
continue | |
method = [','.join(pr.val) for pr in route.predicates if isinstance(pr, RequestMethodPredicate)][0] | |
json_routes.append((route.name, route.pattern, method)) | |
for route in json_routes: | |
print(route) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment