Ticket #12906: allow_variable_in_url_templatetag.diff

File allow_variable_in_url_templatetag.diff, 1.6 KB (added by Guillermo Gutiérrez, 15 years ago)
  • django/template/defaulttags.py

    old new  
    366366        kwargs = dict([(smart_str(k,'ascii'), v.resolve(context))
    367367                       for k, v in self.kwargs.items()])
    368368
     369        # Try to resolve view_name as Variable, failing silently.
     370        try:
     371            view_name = Variable(self.view_name).resolve(context)
     372        except VariableDoesNotExist:
     373            view_name = self.view_name
     374
    369375        # Try to look up the URL twice: once given the view name, and again
    370376        # relative to what we guess is the "main" app. If they both fail,
    371377        # re-raise the NoReverseMatch unless we're using the
    372378        # {% url ... as var %} construct in which cause return nothing.
    373379        url = ''
    374380        try:
    375             url = reverse(self.view_name, args=args, kwargs=kwargs, current_app=context.current_app)
     381            url = reverse(view_name, args=args, kwargs=kwargs, current_app=context.current_app)
    376382        except NoReverseMatch, e:
    377383            if settings.SETTINGS_MODULE:
    378384                project_name = settings.SETTINGS_MODULE.split('.')[0]
    379385                try:
    380                     url = reverse(project_name + '.' + self.view_name,
     386                    url = reverse(project_name + '.' + view_name,
    381387                              args=args, kwargs=kwargs, current_app=context.current_app)
    382388                except NoReverseMatch:
    383389                    if self.asvar is None:
Back to Top