如何使用{}为模板的部分禁用Jinja2? [英] How to disable Jinja2 for sections of template with {}?
问题描述
我通过复制/粘贴他们在其网站上提供的代码在页面上添加了一个Facebook按钮.
I added a facebook button to my page by copying/pasting the code they supply on their website.
它看起来像这样:
"http://www.facebook.com/dialog/feed?app_id={{fbapp_id}}&link={{link_url}}&message={{share_message|urlencode}}&display=popup&redirect_uri={{link_url}}
如您所见,在其中找到了Jinja
的{}
.但是,由于我不希望将以上任何代码替换为任何东西,因此我可以在模板中添加一些内容,以指示Jinja
忽略定界符之间的所有内容吗?
As you can see, it's got the {}
in there that Jinja
looks for. However, being that I don't want any of the above code replaced with anything, is there something I can add into my template which tells Jinja
to ignore everything between the delimiters?
Python处理程序:
Python Handler:
class MainHandler(webapp2.RequestHandler):
def get(self):
template = JINJA_ENV.get_template('index.html')
self.response.write(template.render(None))
推荐答案
您通常可以找到该信息在文档的转义"下或类似内容.在这种情况下,您可以输出带有变量表达式的定界符:
You can usually find that information in the documentation, under "Escaping" or similar. In this case, you can either output the delimiter with a variable expression:
{{ '{{' }}
或者您可以使用raw
块来获取更长的代码段:
Or you can use the raw
block, for longer stretches of code:
{% raw %}
<ul>
{% for item in seq %}
<li>{{ item }}</li>
{% endfor %}
</ul>
{% endraw %}
这篇关于如何使用{}为模板的部分禁用Jinja2?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!