简体   繁体   中英

Jinja2 Import Static HTML in Pyramid

My application contains Angular code. I want Jinja2 templating within the layout, but need to be able to use Angular expressions within the page. I'd like to do that by importing a static HTML file into the main Jinja2 template that is not parsed .

How can I import an HTML template file without parsing it? A Jinja2 extension? If so, how?

When you say "import", do you mean copying it in by hand, or do you mean you have some HTML in another file that you'd like injected (unparsed) somewhere within the template?

If it's the latter you're after -- including an HTML file without parsing -- you could write an extension, sure, but it's far simpler to just put the file's contents into a context variable (named, say, rawHtml ) and output it like so:

{{ rawHtml }}

On the other hand, if you're writing the HTML inside the template itself and you want it rendered without interpretation, you can accomplish that too by using the raw construct :

{% raw %}
    <a href="#">He had a great moustache, like this :-{ </a>
{% endraw %}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM