Show all Flask Routes
One of my favorite things about rails is rake routes
. This command will show you all of the routes that your application is currently aware of. I was searching for something similar in Flask and came across this snippet. Sadly, it did not work for me. I am using Python 3, so that may have something to do with it. In any case, I did not have time to dig into what was wrong, because just the other day I read this amazing introduction to functional python where my biggest take away was that as soon as you see multiple for loops, its time to use map
. With my functional skills in tow, I wrote a simple one liner to print all of my routes.
@manager.command def routes(): import pprint pprint.pprint(list(map(lambda x: repr(x), app.url_map.iter_rules())))
[levlaz braindump]$ python3 manage.py routes ["<Rule '/auth/change-password' (GET, HEAD, OPTIONS, POST) -> " 'auth.change_password>', "<Rule '/auth/change-email' (GET, HEAD, OPTIONS, POST) -> " 'auth.change_email_request>', "<Rule '/auth/unconfirmed' (GET, HEAD, OPTIONS) -> auth.unconfirmed>", "<Rule '/auth/register' (GET, HEAD, OPTIONS, POST) -> auth.register>", "<Rule '/auth/confirm' (GET, HEAD, OPTIONS) -> auth.resend_confirmation>", "<Rule '/auth/logout' (GET, HEAD, OPTIONS) -> auth.logout>", "<Rule '/auth/login' (GET, HEAD, OPTIONS, POST) -> auth.login>", "<Rule '/auth/reset' (GET, HEAD, OPTIONS, POST) -> " 'auth.password_reset_request>', "<Rule '/empty-trash' (GET, HEAD, OPTIONS) -> main.empty_trash>", "<Rule '/notebooks' (GET, HEAD, OPTIONS, POST) -> main.notebooks>", "<Rule '/favorites' (GET, HEAD, OPTIONS) -> main.favorites>", "<Rule '/settings' (GET, HEAD, OPTIONS) -> main.settings>", "<Rule '/shutdown' (GET, HEAD, OPTIONS) -> main.server_shutdown>", "<Rule '/archive' (GET, HEAD, OPTIONS) -> main.view_archive>", "<Rule '/search' (GET, HEAD, OPTIONS) -> main.search>", "<Rule '/trash' (GET, HEAD, OPTIONS) -> main.trash>", "<Rule '/add' (GET, HEAD, OPTIONS, POST) -> main.add>", "<Rule '/' (GET, HEAD, OPTIONS, POST) -> main.index>", "<Rule '/static/bootstrap/<filename>' (GET, HEAD, OPTIONS) -> " 'bootstrap.static>', "<Rule '/auth/change-email/<token>' (GET, HEAD, OPTIONS) -> " 'auth.change_email>', "<Rule '/auth/confirm/<token>' (GET, HEAD, OPTIONS) -> auth.confirm>", "<Rule '/auth/reset/<token>' (GET, HEAD, OPTIONS, POST) -> " 'auth.password_reset>', "<Rule '/delete-forever/<id>' (GET, HEAD, OPTIONS, POST) -> " 'main.delete_forever>', "<Rule '/notebook/<id>' (GET, HEAD, OPTIONS) -> main.notebook>", "<Rule '/notebook/<id>' (DELETE, OPTIONS) -> main.delete_notebook>", "<Rule '/favorite/<id>' (GET, HEAD, OPTIONS, POST) -> main.favorite>", "<Rule '/restore/<id>' (GET, HEAD, OPTIONS, POST) -> main.restore>", "<Rule '/archive/<id>' (GET, HEAD, OPTIONS) -> main.archive>", "<Rule '/delete/<id>' (GET, HEAD, OPTIONS, POST) -> main.delete>", "<Rule '/static/<filename>' (GET, HEAD, OPTIONS) -> static>", "<Rule '/share/<id>' (GET, HEAD, OPTIONS, POST) -> main.share>", "<Rule '/note/<id>' (GET, HEAD, OPTIONS) -> main.note>", "<Rule '/edit/<id>' (PUT, OPTIONS) -> main.edit>", "<Rule '/tag/<name>' (GET, HEAD, OPTIONS) -> main.tag>"]
Thank you for reading! Share your thoughts with me on mastodon or via email.
Check out some more stuff to read down below.
Most popular posts this month
- Dagger Feels Like Magic
- Setting up ANTLR4 on Windows
- SQLite DB Migrations with PRAGMA user_version
- 20 Years of Ubuntu
- видно по глазам - you can see it in the eyes
Recent Favorite Blog Posts
This is a collection of the last 8 posts that I bookmarked.
- Serendipity from Armin Ronacher's Thoughts and Writings
- Andrea Veri: GNOME Infrastructure migration to AWS from Planet GNOME
- A Whale of a Time from https://popagandhi.com/
- Pluralistic: You should be using an RSS reader (16 Oct 2024) from Pluralistic: Daily links from Cory Doctorow
- Sahil Dhiman: 25, A Quarter of a Century Later from Planet Debian
- Reflections on Palantir from Nabeel S. Qureshi
- Reading Old Posts from Kev Quirk
- Capture less than you create from David Heinemeier Hansson
Articles from blogs I follow around the net
Script Doctoring
I’ve been having a number of communications problems in my interactions with my doctors at Kaiser lately, and it’s becoming one of those things where the burden and onus entirely is placed upon me to sort out, and that’s exhausting for the actually autist…
via Bix Dot Blog October 22, 2024Blockchain company Forte acquires games studios, demands secrecy, shuts them down
Sometime in 2023, blockchain firm Forte acquired game studios Phoenix Labs and Rumble Games. However, it would be a year before this came to light, because according to a report from Game Developer, Forte demanded secrecy from employ…
via Web3 is Going Just Great October 22, 2024Initial explorations of Anthropic's new Computer Use capability
Two big announcements from Anthropic today: a new Claude 3.5 Sonnet model and a new API mode that they are calling computer use. (They also pre-announced Haiku 3.5, but that's not available yet so I'm ignoring it until I can try it out myself.) Comp…
via Simon Willison's Weblog: Entries October 22, 2024Generated by openring