librelist archives

« back to archive

Weird issue with using jinja set and url_for

Weird issue with using jinja set and url_for

From:
Mmn
Date:
2012-06-29 @ 06:22
Hello,

I was refactoring my templates to use macros so that the templates are
shorter and maintainability improves. So for certain ui elements, I am
passing the url they should point to from one template.

So whenever I do
{% set onclick_url="url_for('customer_blueprint.relation_addresses',
user_id=session.get('user').id, relation_id=rel.id)" %}, it is always
setting the onclick_url as the text given in quotes and not the resolved
url. I tried putting {{}} around the url_for also and various other quote
options - none seem to work. This value is passed into a macro

Can someone please telll me how I can achieve this?

Regards,
-- 
--
It’'s a fact, taller people sleep longer in bed.

Re: [flask] Weird issue with using jinja set and url_for

From:
Simon Sapin
Date:
2012-06-29 @ 06:51
Le 29/06/2012 08:22, MMN a écrit :
> {% set onclick_url="url_for('customer_blueprint.relation_addresses',
> user_id=session.get('user').id, relation_id=rel.id <http://rel.id>)" %}

Hi,

Think of `expr` in {% set name = expr %} as a Python expression. If you 
use quotes you will get a string. If you want the expression to be a 
function call, do not surround it in quotes:

{% set onclick_url = url_for(...) %}

Regards,
-- 
Simon Sapin