TL;DR: I accidentally wrote an argparse for web framework views. You can get it here.
What?
Do you care about your query strings? Do you like them to look nice? Do you find yourself repeatedly writing code to validate parameter values?
Well, I recently got annoyed with repeatedly solving those problems for myself in my Django-based site and wrote a nice solution that I thought others might find useful.
Why?
First, let me lay out the problems I wanted to solve:
- I’d like to omit parameters that are already the default.
- I’d like to have the parameters in a preferred order.
- I kept having to write code to cast GET parameter values into a certain type and check that they’re valid.
- My code didn’t make it very clear what the potential parameters were for each view, what their types were, and what their defaults were.
To expand on #1: my webapps often use query strings. But it’s true that query strings are ugly and I’d like beautiful urls. So when possible, I’d like to minimize the query strings by omitting default parameters. Most of the time, my apps need few or no non-default parameters, so this point is significant.