-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Rooted UrlDispatcher / Mini Applications #780
Comments
I thought about problem like this for a long time. |
Do you mean I doubt if it good idea, better to support nested routes with unmodified paths given from request. Otherwise printing debug info with unprefixed paths makes a mess. |
Yes, that is what I had in mind.
I completely agree. I'm just impatient and want a workaround. It's a much better idea to support nested routes directly (and leave the request object immutable). |
Hi, it would be great to have ability to include many routes in one (like in Django :).
@asvetlov what do you think about this solution? To my mind it is very ugly and buggy, but it works for my case. If you have idea how to write it in right way, but have no time for realization, so tell us, maybe we can try to write smth and send PR. |
May I ask what the status on this "nested"-router feature is? |
I'm working on it. |
Fixed by #1301 |
@asvetlov thanks for realization, as I can see from documentation we need to create additional application and add those application to existing route, to my mind it's a complex solution, what about just creating a new
You solution very useful in cases when we need something big with middlewares, signals, etc. But in many cases we need something simple like in my example. I can try to create solution like I see it and send you PR, what do you think? |
No. Subapplications are required exactly because app is an container for its global state, signals and middlewares.
Sub-routers make overcomplication. |
Looks like solution, but not very useful to my mind. Let's imaging big routing configuration, this is example using
It's easy to read and I can reverse urls using: Using your way I need to write additional helpers (sometimes very complex) in each project. I know |
Are you really asking for nested routes or namespaces for url reversing? |
Why I want
In top level router I just want something like this:
In this case I don't want to create additional apps for My proposal is more about project organization and how |
Well, I need to sleep on it. |
Done #1343 |
Currently, each
Application
has a single router instance (UrlDispatcher
by default). This works fine for small applications.Express (of node.js) has the convenient router class which expands on this functionality. Specifically, Express allows the user to create "mini applications" which can be assigned (re-rooted) to a given path. I think that aiohttp could benefit from similar functionality.
That is, instead of having the following calls:
One could have something like a rooted
UrlDispatcher
/ mini application:and then later simply:
Note that all the calls to
/blog/*
will be forwarded to theBlog
class. Thus one can keep all the resources (e.g., database, template files) belonging to the blog inside the Blog class. Also, one can easily re-root the entire Blog "mini application" by changing only a single line of code.The
RootedUrlDispatcher
is just a suggestion. Any way of implementing mini applications would be a nice addition to aiohttp.The text was updated successfully, but these errors were encountered: