Comments (5)
Oh my, an organic user, things just got trill.
So I polled some Werkzeug users around me and I didn't have very many takers/users of most of Werkzeug's routing abstractions. In fact, it's caused some major issues, like #3. (In further fact, I've got some branches with some lighter-weight routing designs I've been putting together.)
Specifically when you say building URLs, do you mean like treating them as templates, sort of like "reverse()"? Or some form of simple redirect? Because you can definitely access the current URL via the Request object. So, one or two concrete use cases would be useful. I'd also be interested in your opinions on Werkzeug's routing abstractions. Much/most of the complexity seems to be in support of rather passe features like dynamic subdomain routing (i.e., alecthomas.mysite.com), which could be better achieved via web server rewriting, but probably shouldn't be done at all (security issues, cookies).
Mahmoud
from clastic.
PS Voluptuous is pretty awesome. A form-parsing middleware based on it has been on my TODO pretty much since day 1. So also thanks ;)
from clastic.
Sorry, yeah, I am referring to reconstructing a URL from a Route. Equivalent to Flask's url_for(endpoint, **values)
.
FWIW, I don't use any complex features of Werkzeug's routing at all, so I wouldn't miss them at all.
Glad you like Voluptuous!
from clastic.
Ah, yes, I've frequently had this on my mind. There is a caveat though, while that would be possible/straightforward to add in, with Clastic it's very easy to have multiple Routes using the same endpoint function. An easy example would be something along the lines of /job/<id>/
and /job/<id>/json/
, the former which returns HTML, the latter JSON, but both point at the same endpoint function.
Anyways, I've also found it kind of confusing because while Clastic enables this sort of collision, it's not unique in the slightest. See this StackOverflow question, for instance (don't get DPR'd). And then if we get into naming URLs, well, now you've got two conventions to manage (URLs and URL names). In my Django days I saw way too many templates taken down because of a missed urlresolvers.reverse()
call.
That said, it probably wouldn't be a big deal to add a caveat-emptor url_for(), if we can answer a couple questions. Here's what I'm thinking:
def get_foo(_application, foo_id):
return redirect(_application.get_url_for(get_other, bar_id=foo_id))
def get_other(bar_id):
return 'result'
As you can see, the Application would fulfill the role of URL map/adapter, and facilitates these sorts of lookups. Now, the question is: if there are multiple URLs with that endpoint, would you rather I raise an exception or just return the first? Routes could also be name-able, but is it worth the syntax overhead?
from clastic.
Yeah, in Flask I have always been rigorous about using IDs everywhere and using those in url_for. It works well, but you do have to be a bit more disciplined.
from clastic.
Related Issues (14)
- Server Reload Fails when Indentation Error is Encountered HOT 3
- Paths are not matched in order HOT 2
- Not compatible with Werkzeug 0.11.11 HOT 6
- Python 3 support HOT 3
- Dynamic binding example doesn't work HOT 1
- WhiteNoise middleware for static files? HOT 4
- More documentation HOT 3
- Sending Responses Later HOT 6
- App Level Middleware Invocation and Route Ordering HOT 5
- Accessing POST JSON and a requests raw body HOT 4
- Accessing Secure Cookie in request HOT 5
- Recent failing HOT 3
- Drop official support for Python 3.7, add Python 3.12
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from clastic.