Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Ticket #2449 (closed defect: wontfix)

Opened 9 years ago

Last modified 9 years ago

Template Namespace and `url`

Reported by: rpetrello Owned by:
Priority: normal Milestone: 2.1rc1
Component: TurboGears Version: 2.1a3
Severity: normal Keywords:
Cc:

Description

I've just noticed this in TG2.1a3, verified in a recent quickstarted project:

It seems that any @exposed() controller that uses the key url in its namespace, e.g.:

    @expose('genshibug.templates.index')
    def index(self):
        """Handle the front-page."""
        return dict(page='index', url='http://google.com')

...the value for url is always overwritten w/ <routes.util.URLGenerator object at 0x10422c8d0>. Is this expected behavior? Maybe some form of misconfiguration?

Change History

comment:1 Changed 9 years ago by percious

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

yes, this is expected behavior because pylons writes the url function into the namespace before rendering the template. We cannot change the way this functions because it will break API for many people.

comment:2 Changed 9 years ago by mramm

  • Status changed from closed to reopened
  • Resolution wontfix deleted
  • Severity changed from minor to normal

This is not done by pylons, it's done in the tg rendering code, and it seems like it's the reverse of what *should* be happening.

The standard variables should be overwritten by the ones that come from the user's return dictionary, not the other way round.

I think this is a very small fix.

comment:3 Changed 9 years ago by chrisz

  • Milestone changed from __unclassified__ to 2.1rc1

comment:4 Changed 9 years ago by rick446

  • Status changed from reopened to closed
  • Resolution set to wontfix

Actually, Mark, you are wrong ;-) . Pylons (pylons.templating) is the culprit here:

def render_genshi(template_name, extra_vars=None, cache_key=None, 
                  cache_type=None, cache_expire=None, method='xhtml'):
    """Render a template with Genshi
    
    Accepts the cache options ``cache_key``, ``cache_type``, and
    ``cache_expire`` in addition to method which are passed to Genshi's
    render function.
    
    """
    # Create a render callable for the cache function
    def render_template():
        # Pull in extra vars if needed
        globs = extra_vars or {}
        
        # Second, get the globals
        globs.update(pylons_globals())

        # Grab a template reference
        template = globs['app_globals'].genshi_loader.load(template_name)
        
        return literal(template.generate(**globs).render(method=method,
                                                         encoding=None))
    
    return cached_template(template_name, render_template, cache_key=cache_key,
                           cache_type=cache_type, cache_expire=cache_expire,
                           ns_options=('method'), method=method)
Note: See TracTickets for help on using tickets.