#5034: request.urlconf does not get used in URL template tag
---------------------------------------------+------------------------------
          Reporter:  Trey                    |         Owner:  SmileyChris      
     
            Status:  new                     |     Milestone:                   
     
         Component:  Core framework          |       Version:  SVN              
     
        Resolution:                          |      Keywords:  url, urlconf, 
override
             Stage:  Design decision needed  |     Has_patch:  1                
     
        Needs_docs:  0                       |   Needs_tests:  0                
     
Needs_better_patch:  0                       |  
---------------------------------------------+------------------------------
Changes (by anonymous):

 * cc: [EMAIL PROTECTED] (added)

Comment:

 I'm sure most of us who pay attention to this ticket are aware of this,
 but the patch here no longer works with trunk.

 It looks like Malcolm might be working on this, but if you need to have
 request aware reversing and want to use trunk, a simple addition to
 get_resolver() in urlresolvers.py and some middleware will make it work.
 This uses threading.local rather than explicitly passing the request.

 First, there's this middleware that I put in django/middleware/request.py:

 {{{
 try:
     from threading import local
 except ImportError:
     from django.utils._threading_local import local

 _thread_locals = local()
 def get_request():
     return getattr(_thread_locals, 'request', None)

 class RequestMiddleware(object):
     """Middleware that saves the current request in thread local
 storage."""
     def process_request(self, request):
         _thread_locals.request = request
 }}}

 Then the change to get_resolver():

 {{{
 from django.middleware.request import get_request

 def get_resolver(urlconf):
     if urlconf is None:
         request = get_request()
         if request:
             urlconf = request.urlconf
     if urlconf is None:
         from django.conf import settings
         urlconf = settings.ROOT_URLCONF
     return RegexURLResolver(r'^/', urlconf)
 }}}

 I've only done minimal testing, but I figured someone looking here might
 want to try this.

-- 
Ticket URL: <http://code.djangoproject.com/ticket/5034#comment:15>
Django Code <http://code.djangoproject.com/>
The web framework for perfectionists with deadlines
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to