-
Notifications
You must be signed in to change notification settings - Fork 886
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
Simple route and view config decorator #2852
Comments
I would very much like to see something like this in core and I pledge to help write code, tests and/or docs. Would make teaching/demoing Pyramid to newcomers simpler. |
This is great and I think it would significantly decrease the barrier of entry. |
I recommend a different name, though. I think |
@JanLikar Updated the propsosal |
I like |
It'd help me a lot to talk at least a little bit about what an "ideal" solution is and see how far we are from that before resolving to settle on resolving issues through documentation. Obviously we have pushed hard against such a feature in Pyramid for a long long time (ever since I've been around, which is 1.0 days) and I haven't seen many proposals on how to fix it - just a lot of requests to make things more like flask. They basically all cut corners, which is fine until it goes into core. Without the weighting it will likely be inferior by design versus flask's solution which uses a typed routing syntax where each type is assigned weights. It should be obvious that this is super important for any route that has a pattern. Another thing to note is that Pyramid already did this once where a) It was confusing which parameters were for the view and which were for the route. Some weren't possible. The old approach was b) A lot of newcomers who saw that code didn't realize you could have more than one view for each route with different predicates (a distinguishing feature of Pyramid). This proposal fixes things partially by namespacing the route options into |
@mmerickel Let me reiterate that this is a solution for very simple routing cases, not all of them.
I am afraid we cannot reach ideal solution here that would solve all the issues, as Pyramid has the most complex routing logic of all the web frameworks out there. For complex use cases it is still better to use For example like use case:
Here To reach a community consensus here, I suggest we now look through our Pyramid project source codes for different route + view config examples and list ones we'd like to cover with |
To resolve ambiguity, raise an error during |
If |
Based on the feedback from @jean and @mfrlin, I have updated the proposal. Based on grepping my various Pyramid based projects using I want the signature to be more static, so that newcomers find it easier and IDEs provide autocompletion. |
The updated signature looks OK to me. |
This is not an easy thing to do at all. It's hard to put any weight on statements like this when no proof of concept has been written on accomplishing the comparison of arbitrary regexes. It sounds great when you say it, but that's about as far as it is helpful.
I feel like you might be conveniently ignoring that we already had a solution for "simple routing cases" that we removed for real reasons dealing with confusion. What exactly makes this proposal better? One of your motivations above is "feature parity with flask". This proposed API is absolutely not that. Can we agree on that? It is in no way usable in the variety of situations that flask's route decorator is usable. I'd really appreciate if some of the other COMMON issues we see with routing were taken into account when proposing a new API, instead of going for the lowest common denominator. For example, fitting routes/views into the security system is by far the #1 question I see about routes on IRC. Another is how to improve REST APIs, and instead this is focused on simple views that handle rendering a template. |
@mmerickel The current Pyramid solution for a view registration is not simple as you need to update two files for adding one view: Do we agree on this or not, as we need to find some common ground to have a starting point? If we do agree on this that there is need for such thing then we can take one step backward and start discussing how we can work towards having this in Pyramid core. |
That would be very hard indeed, but I don't seen any arbitrary regexes, only a simple path like A @miohtama would |
In the end it goes like this
We are now discussing (a) and (b). In the end, it doesn't change the underlying logic of Pyramid. It only makes one manual call to |
Definitely - I wouldn't go through all the effort of analyzing the API if I didn't think it'd be a great feature to add to Pyramid. I've put a lot [1] of thought into how we can even make Pyramid extensible enough to experiment with various ways of solving this. However adding it to core comes at a cost, and I have pretty high standards for what the feature needs to be in order to avoid history repeating itself. I can't justify adding a decorator that is by design inferior to flask's. This exact feature and example that you're proposing is in our core design defense [2] as a Bad Idea (tm). If we can't improve on it to make that design defense invalid, then how can I accept it? Solving this with documentation just isn't good enough to me. [1] http://docs.pylonsproject.org/projects/pyramid/en/latest/narr/extconfig.html#calling-actions-from-actions |
This is only one way of doing it, but nothing in Pyramid forces it. |
I am opening this item here for discussion.
When building small scale websites, most views have only one route to them in the form of simple path. Having a separate call for
@view_config
oradd_view()
and thenadd_route()
is often unnecessary.These could be combined to one
@route_and_view_config
decorator.Example
views.py
:Then in
__init__
:Motivation
All view related configuration in one place, the decorator, instead of being split between
@view_config
inviews.py
andadd_route
in__init__.py
Make development and maintenance easier, especially for newcomers who can get away with less lines and less questions
Feature parity with Flask
Existing implementations
@simple_route
in Websauna (based on latter) https://websauna.org/docs/api/websauna.system.core.route.html?highlight=simple_route#websauna.system.core.route.simple_routeOriginal
tomb_routes
package https://github.com/TombProject/tomb_routesResolving issue between route priorization
In earlier IRC coffee table discussion people have noted that there should be some sort of weight (integer) added to routes, so that routes scanned in different order can be resolved in correct order. Is see this as unnecessary complication to be implemented, but instead suggest to resolve this through documentation. Only use
@route_and_view
for simple cases. If there are competing routes and view configurations then it is suggested to use calls toadd_route
andadd_view
explicitly instead of@route_and_view
approach.Suggested signature
The text was updated successfully, but these errors were encountered: