Pass request object to URL resolvers so custom despatchers can use more than just path.
|Reported by:||alexdutton||Owned by:||nobody|
|Cc:||alexdutton||Triage Stage:||Design decision needed|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
I'd like to serve a site on more than one domain using one instance of a Django app. To do this I was thinking of writing a custom URL resolver that looks at the Host header when despatching.
At the moment I can't get at the header without trawling the stack (yuck), so it would be great if the URL resolver were passed the entire request object to play with. In the case of the built-in resolvers it wouldn't be used, but it'd allow others to extend the resolving process in new and exciting ways.
WRT backwards compatibility it gets a bit fun, as we really don't want to be changing the signature of the resolve method. It might be possible to add a new resolve_request method that takes a request object, not a string. If this doesn't exist on the resolver it tries the current way. Any custom resolvers wouldn't know about the new method, but that would only be an issue if they want to use the new functionality.
This can probably be as simple as replacing the current calls to resolve() with:
try: callback, callback_args, callback_kwargs = resolver.resolve_request(request) except (AttributeError, NotImplementedError), e: callback, callback_args, callback_kwargs = resolver.resolve(request.path_info)
If this is a feature that's looked upon favourably, I'm happy to put a patch together.
Change History (6)
comment:1 Changed 5 years ago by
|Patch needs improvement:||unset|
comment:3 Changed 5 years ago by
|Triage Stage:||Unreviewed → Design decision needed|