Ticket #5034: url_templatetag_urlconf.patch

File url_templatetag_urlconf.patch, 1.1 KB (added by Trey <trey@…>, 8 years ago)

This patch will modify the URLNode class in template/defaulttags.py to use the urlconf in the request context if available.

  • django/template/defaulttags.py

    diff -r -x .svn -U 5 django-src-orig/django/template/defaulttags.py django-src/django/template/defaulttags.py
    old new  
    338338    def render(self, context):
    339339        from django.core.urlresolvers import reverse, NoReverseMatch
    340340        args = [arg.resolve(context) for arg in self.args]
    341341        kwargs = dict([(smart_str(k,'ascii'), v.resolve(context)) for k, v in self.kwargs.items()])
    342342        try:
    343             return reverse(self.view_name, args=args, kwargs=kwargs)
     343            urlconf = None
     344            if 'request' in context and hasattr(context['request'], 'urlconf'):
     345                urlconf = context['request'].urlconf
     346            return reverse(self.view_name, urlconf=urlconf, args=args, kwargs=kwargs)
    344347        except NoReverseMatch:
    345348            try:
    346349                project_name = settings.SETTINGS_MODULE.split('.')[0]
    347350                return reverse(project_name + '.' + self.view_name, args=args, kwargs=kwargs)
    348351            except NoReverseMatch:
Back to Top