Hi,

On 2011-03-21 5:16 AM, Joshua Bronson wrote:
I noticed jinja2/defaults.py sets "dict" to "lambda **kw: kw" in its
DEFAULT_NAMESPACE. Is there a reason why it's not just set to dict?
dict() behaves differently from Python version to Python version and some objects expose some of their inner workings to that function and break the sandbox if enabled. Also the use case of an expanded dict is limited, one better passes different functions to the environment that do not need hackery.

I'd like to do {{ url_for(request.endpoint, **dict(request.view_args,
foo=bar) }} in a template (overriding any "foo" value in the current
page's view_args with "bar"), but I can't with the phony dict function.
You are free to override that function with the builtin dict type. However for that particular use case I recommend something like this:

def modified_url_for(**updates):
    args = request.view_args.copy()
    args.update(updates)
    return url_for(request.endpoint, **args)
app.jinja_env.globals['modified_url_for'] = modified_url_for

And the in the template:

    <a href="{{ modified_url_for(page=2) }}">Page 2</a>



Regards,
Armin

--
You received this message because you are subscribed to the Google Groups 
"pocoo-libs" 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/pocoo-libs?hl=en.

Reply via email to