• Now all data be ready for publish, We had made our blog alive now. Haha.

  • These days CCP GFW blocked all the IPs from US and when I switch my IP in google Cloud, the disk data cannot be restore again. I have to restart my blog totally, Now the website is still building…

Reference template variable within Jinja expression- Stack Overflow

Python PingBook 1 months ago (10-23) 17 0


I have a route defined like this:

def moremagic(filename):

And now in a template I want to call that route using url_for() like so:

you uploaded {{ name }}

‘) }}”>Click to see magic happen

I have tried:

Click to see magic happen

That throws a jinja2.TemplateSyntaxError: expected token ‘:’ got }

Can anyone suggest how to get the {{ name }} that appears in the template into the url_for() so that when I click I call the correct app.route?


Everything inside the {{ … }} is a Python-like expression. You don’t need to use another {{ … }} inside that to reference variables.

Drop the extra brackets:

you uploaded {{ name }}

Click to see magic happen

(Note that the url_for() function takes the endpoint name, not a URL path; the name defaults to the name of the function, moremagic in your example).

Copyright from PingBook Blog, If not specified, they are original. This site uses BY-NC-SAProtocol authenticated.
For reprinting, please indicate the link of the original text:Reference template variable within Jinja expression- Stack Overflow
LIKE (0)

We create, We sharing! Tag every value data your sharing
Submit comments
Cancel comments
emoji picture bold strikethrough center italic check in

Hi,you need to provide your name and email adress!

  • Name (Required)
  • Email (Required)
  • Website