-
-
Notifications
You must be signed in to change notification settings - Fork 822
Support URLRouter with include #2110
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
base: main
Are you sure you want to change the base?
Changes from 7 commits
cc4a598
98de0a2
5309e68
b9b0c76
436d38a
4b47981
1890cd8
9d4feeb
504bd3c
76260f7
7ca0037
4df1d5f
cdc8c6c
e35c2d5
e3e411f
3376bb2
88ddd77
758a205
dd4b1aa
29c7402
74e5ee2
05a869a
6773674
a303572
c2b5ee0
67d5240
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,10 @@ | ||
| import importlib | ||
| import re | ||
|
|
||
| from django.conf import settings | ||
| from django.core.exceptions import ImproperlyConfigured | ||
| from django.urls.exceptions import Resolver404 | ||
| from django.urls.resolvers import RegexPattern, RoutePattern, URLResolver | ||
| from django.urls.resolvers import RegexPattern, RoutePattern, URLResolver, URLPattern | ||
|
|
||
| """ | ||
| All Routing instances inside this file are also valid ASGI applications - with | ||
|
|
@@ -67,7 +68,32 @@ class URLRouter: | |
| _path_routing = True | ||
|
|
||
| def __init__(self, routes): | ||
| self.routes = routes | ||
| new_routes = [] | ||
| for route in routes: | ||
| if not route.callback and isinstance(route, URLResolver): | ||
| for url_pattern in route.url_patterns: | ||
| url_pattern: URLPattern | ||
| # concatenate parent's url and child's url | ||
| regex = "".join( | ||
| x.pattern | ||
| for x in [route.pattern.regex, url_pattern.pattern.regex] | ||
| ) | ||
| regex = re.sub(r"(/)\1+", r"\1", regex) | ||
|
||
| name = ( | ||
| f"{route.app_name}:{url_pattern.name}" | ||
| if url_pattern.name | ||
| else None | ||
| ) | ||
| pattern = RegexPattern(regex, name=name, is_endpoint=True) | ||
| new_routes.append( | ||
| URLPattern( | ||
| pattern, url_pattern.callback, route.default_kwargs, name | ||
bigfootjon marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ) | ||
| ) | ||
| else: | ||
| new_routes.append(route) | ||
|
|
||
| self.routes = new_routes | ||
|
|
||
| for route in self.routes: | ||
| # The inner ASGI app wants to do additional routing, route | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.