-
-
Notifications
You must be signed in to change notification settings - Fork 16.7k
Add routes command to flask cli #2092
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Conversation
This file contains hidden or 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
Running `flask routes` will list all registered routes for a given app, sorted by endpoint Signed-off-by: Will Soto <will.soto9@gmail.com>
ThiefMaster
reviewed
Nov 20, 2016
flask/cli.py
Outdated
| sorted_rules = sorted(app.url_map.iter_rules(), key=lambda rule: rule.endpoint) | ||
|
|
||
| for rule in sorted_rules: | ||
| methods = ', '.join(rule.methods.difference(ignored_methods)) |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
Signed-off-by: Will Soto <will.soto9@gmail.com>
ThiefMaster
reviewed
Nov 20, 2016
tests/test_cli.py
Outdated
| output = [line.strip() for line in result.output.split('\n')] | ||
|
|
||
| assert result.exit_code == 0 | ||
| assert output[0] == 'routes_blueprint.posts_routes PUT, DELETE, GET /posts/<post_id>' |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
ThiefMaster
reviewed
Nov 20, 2016
|
|
||
| assert result.exit_code == 0 | ||
| assert output[0] == 'routes_blueprint.posts_routes PUT, DELETE, GET /posts/<post_id>' | ||
| assert output[1] == 'routes_blueprint.user_id_route DELETE, GET /users/<user_id>' |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
Signed-off-by: Will Soto <will.soto9@gmail.com>
ThiefMaster
reviewed
Nov 20, 2016
flask/cli.py
Outdated
| app = _app_ctx_stack.top.app | ||
| routes = [] | ||
| ignored_methods = set(['HEAD', 'OPTIONS']) | ||
| sorted_rules = sorted(app.url_map.iter_rules(), key=lambda rule: rule.endpoint) |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
Signed-off-by: Will Soto <will.soto9@gmail.com>
Author
|
@ThiefMaster Thanks for the feedback. I've made all the changes you requested. |
use click.echo instead of print add changelog
Merged
Member
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Running
flask routeswill list all registered routes for a given app, sorted by endpointInspired by
mix phoenix.routes, this will display a list of all registered routes in an application. This is basically #1446, but I have updated it and made it "dumber".NB: I know that the other PR is old and there doesn't seem to be much enthusiasm for it, but I do think this is useful to have to get a high level overview of application routes, especially if they are being generated programmatically.
Example output:
$ flask routes api.me GET /api/users/me/ api.users GET /api/users/ POST /api/users/ PUT, DELETE, GET /api/users/<pk> api.users_schema GET /api/users/schema/ auth_blueprint.authorized GET /login/authorized auth_blueprint.do_login GET /do-login auth_blueprint.login GET /login auth_blueprint.logout GET /logout auth_blueprint.lr_test GET /lr static GET /static/<path:filename>