jinja2 partial escape {% and '

111 Views Asked by At

i want to escape the following complete string using jinja2

{% set src_pk = metadata_dict['src_pk'] -%}

the following works, iam using double quotes

{{"{% set source_model = metadata_dict['source_model'] -%}"}}

however i want to change the ['source_model'] dynamically so i tried the following and none of them seems to work

  1. {{"{% set source_model = metadata_dict['{{POLICY_HK}}'] -%}"}}, which does not work and print it out as is.

  2. {{"{% set source_model = metadata_dict['"+ {{ POLICY_HK }} +"'] -%}"}}
    jinja2.exceptions.TemplateSyntaxError: expected token ':', got '}'

  3. {{"{% set source_model = metadata_dict["+''{{ POLICY_HK }}+''"] -%}"}} expected token 'end of print statement', got '{'

any pointers please?

Thanks -Nen

0

There are 0 best solutions below