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
Cannot nest dispatch applications below traversal application #1350
Comments
Pyramid's router always runs the dispatch step before the traversal step. The only way that this is possible right now would be to mount a new dispatch-based app inside a view, using p.wsgi.wsgiapp2, which is matched via traversal. At this point they are then separate applications and so Pyramid will not be helping you generate urls between them without a custom url generator that knows about both app registries. |
Well that sounds like something that should be changed. How about it, what is keeping you back? |
What is keeping me back? It runs counter to a fundamental design pattern in the dispatch system and other than talking about it technically I don't see much of a use-case for the new pattern. Your multi-language scenario doesn't really sound like something that requires traversal. Do different languages have different levels of depth in the tree? If it is just a small part of a fixed url and you need to use that part of the url in a common way, that's trivial to do via a |
I would have guessed that being able to mount arbitrary pyramid applications at arbitrary urls would be a pretty strong argument. Then again, maybe it would be better to support mounting arbitrary wsgi apps instead to not enforce that the other app is also a pyramid app (I have no clue if and how to support url generation in that case though). |
It's possible to mount wsgi applications at traversal or dispatch endpoints using Perhaps |
http://docs.pylonsproject.org/projects/pyramid/en/latest/narr/hybrid.html#hybrid-chapter lays out how to nest a traversal based application inside a dispatch based application.
However the reverse seems to be missing (or is completely undocumented).
That is, I want to mount a dispatch based application inside a traversal application.
For this to work transparently, request.route_url() and request.route_path() need to be aware of this nesting and let part of the url generation be controlled by the parent application.
Now for some use cases: In our app we have a simple dispatch based admin interface that we now would like to extend with multi language editing capabilities. Switching the admin interface over to a traversal based approach seems sensible, but is not something we would like to commit to in one run before we understand dispatch better.
Thus we had the idea that if we are able to mount the dispatch base admin application below a traversal based layer that allows choosing the language, we will not have to change much in the existing application if we can handle the internationalized access at the model layer. This could work if the traversal based language chooser sets a thread local with the currently selected language, which is then used by the model layer to bring up the right translation.
This seemed like a great first step to get our feet wet with traversal while having a quite natural and small extension to our app.
However, according to the docs this doesn't seem to be possible.
Are the docs incomplete? Is this actually possible? If not, is there a reason why this is not arbitrarily composable? It seems natural that different applications might want to be mounted in arbitrary places into each other and should not need to be aware where and how they are mounted when generating urls.
The text was updated successfully, but these errors were encountered: