Opened 13 years ago

Closed 12 years ago

#16139 closed New feature (duplicate)

Pass request object to URL resolvers so custom despatchers can use more than just path.

Reported by: alexdutton Owned by: nobody
Component: Core (URLs) Version: 1.3
Severity: Normal Keywords: urlresolver
Cc: alexdutton Triage Stage: Design decision needed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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 by alexdutton, 13 years ago

Cc: alexdutton added

Sorry; got my username wrong. If the reporter can be changed to 'alexdutton' that'd be awesome :-).

comment:2 by Aymeric Augustin, 13 years ago

Reporter: changed from Alexander Dutton to alexdutton

comment:3 by Aymeric Augustin, 13 years ago

Triage Stage: UnreviewedDesign decision needed

First, I'd suggest you take a look at https://github.com/jezdez/django-hosts - this could well be the future of multi-domain support in Django, which is what you really need.

Then, I think this kind of change on an extremely central component should be discussed on the mailing list => DDN.

Version 0, edited 13 years ago by Aymeric Augustin (next)

comment:4 by Aymeric Augustin, 13 years ago

UI/UX: unset

Change UI/UX from NULL to False.

comment:5 by Aymeric Augustin, 12 years ago

Component: Core (Other)Core (URLs)

comment:6 by Aymeric Augustin, 12 years ago

Resolution: duplicate
Status: newclosed

The feature requested here is the same as #8896.

Note: See TracTickets for help on using tickets.
Back to Top