Code

Opened 3 years ago

Closed 16 months 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.

Attachments (0)

Change History (6)

comment:1 Changed 3 years ago by alexdutton

  • Cc alexdutton added
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

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

comment:2 Changed 3 years ago by aaugustin

  • Reporter changed from alexsdutton to alexdutton

comment:3 Changed 3 years ago by aaugustin

  • Triage Stage changed from Unreviewed to Design 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 3 years ago by aaugustin (next)

comment:4 Changed 2 years ago by aaugustin

  • UI/UX unset

Change UI/UX from NULL to False.

comment:5 Changed 16 months ago by aaugustin

  • Component changed from Core (Other) to Core (URLs)

comment:6 Changed 16 months ago by aaugustin

  • Resolution set to duplicate
  • Status changed from new to closed

The feature requested here is the same as #8896.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.