jinja2

Render HTML tags from variable without escaping [duplicate]

邮差的信 提交于 2021-02-19 02:12:57
问题 This question already has answers here : Passing HTML to template using Flask/Jinja2 (6 answers) Closed 5 years ago . I have some HTML content that I want to pass to the template to render. However, it escapes the tags to use HTML entities ( < ), so they show up as code rather than markup. How can I render the html passed to the template? tags = """<p>some text here</p>""" render_template ('index.html',tags=tags) {{ tags }} '< some text here >' I want a paragraph with the text though. some

Render HTML tags from variable without escaping [duplicate]

主宰稳场 提交于 2021-02-19 02:11:26
问题 This question already has answers here : Passing HTML to template using Flask/Jinja2 (6 answers) Closed 5 years ago . I have some HTML content that I want to pass to the template to render. However, it escapes the tags to use HTML entities ( < ), so they show up as code rather than markup. How can I render the html passed to the template? tags = """<p>some text here</p>""" render_template ('index.html',tags=tags) {{ tags }} '< some text here >' I want a paragraph with the text though. some

Render HTML tags from variable without escaping [duplicate]

你离开我真会死。 提交于 2021-02-19 02:10:43
问题 This question already has answers here : Passing HTML to template using Flask/Jinja2 (6 answers) Closed 5 years ago . I have some HTML content that I want to pass to the template to render. However, it escapes the tags to use HTML entities ( < ), so they show up as code rather than markup. How can I render the html passed to the template? tags = """<p>some text here</p>""" render_template ('index.html',tags=tags) {{ tags }} '< some text here >' I want a paragraph with the text though. some

jinja2 load template from string: TypeError: no loader for this environment specified

醉酒当歌 提交于 2021-02-18 19:53:30
问题 I'm using Jinja2 in Flask. I want to render a template from a string. I tried the following 2 methods: rtemplate = jinja2.Environment().from_string(myString) data = rtemplate.render(**data) and rtemplate = jinja2.Template(myString) data = rtemplate.render(**data) However both methods return: TypeError: no loader for this environment specified I checked the manual and this url: https://gist.github.com/wrunk/1317933 However nowhere is specified to select a loader when using a string. 回答1: You

jinja2 load template from string: TypeError: no loader for this environment specified

耗尽温柔 提交于 2021-02-18 19:52:25
问题 I'm using Jinja2 in Flask. I want to render a template from a string. I tried the following 2 methods: rtemplate = jinja2.Environment().from_string(myString) data = rtemplate.render(**data) and rtemplate = jinja2.Template(myString) data = rtemplate.render(**data) However both methods return: TypeError: no loader for this environment specified I checked the manual and this url: https://gist.github.com/wrunk/1317933 However nowhere is specified to select a loader when using a string. 回答1: You

How to mock `current_user` in flask templates?

女生的网名这么多〃 提交于 2021-02-18 11:36:54
问题 I want to mock flask-login 's current_user under the template rendering. This function return the current logged user. Right now I'm mocking the AnnonymousUserMixin from flask-login which is returned by default if the user is not authenticated. But this leads to all kind of juggles. If I could simply mock current_user I would be able to create a Mocked object for it to return. Here a sample of what I'm using today: import unnittest from flask_login.mixins import AnonymousUserMixin class

Displaying nested dictionary in Jinja2

一世执手 提交于 2021-02-18 08:16:25
问题 I have the following Jinja2 template: {% block body %} {% for key in tree recursive %} {% set outer_loop = loop %} {% for subkey in tree[key] %} {% if subkey == 'R' %} {{ tree[key][subkey] }} {% else %} {{ outer_loop(dict([(subkey, tree[key][subkey])])) }} {% endif %} {% endfor %} {% endfor %} {% endblock body %} where tree is a Python dictionary such as: tree = {"A": {"R": [1, 2, 3], "B": {"R": [4, 5, 6]}}} and dict() is the Python library function. The issue is that the template displays

ansible Jinja2 JSON loop last elements

梦想与她 提交于 2021-02-16 20:09:26
问题 Im trying to produce a JSON file from a Jinja2 template using variables passed from Ansible. As far as I know there are no modules that help me here (stand to be corrected?). Im stuck on the last loop { "items": [ {% for host in hostvars %} {"apiversion": "v1", "lastrunupdate": "{{ hostvars[host]['date'] }}", "hostname": "null", "hostip": "{{ hostvars[host]['inventory_hostname'] }}", "whoami": "{{ hostvars[host]['whoamiraw'] }}", "serialnumber": "{{ hostvars[host]['serial'] }}", "version": "{

Using data saved as a variable in HTML from Python

醉酒当歌 提交于 2021-02-15 07:50:37
问题 Is it possible to have a variable that is defined in a python file be passed through to a html file in the same directory and used in a 'script' tag? Synopsis: Im producing a flask website that pulls data from a database and uses it to create a line chart in chartjs. Flask uses jijna to manage templates. The data in the databse has been normalised so that it can be read by the chart script (label is in a list, data as a tuple). So far I have produced routes so that each page can be accessed

Override Airflow's default admin index page

此生再无相见时 提交于 2021-02-11 16:49:57
问题 I have created a Airflow plugin which creates a new Menu named Test Plugin and add a submenu Test View so clicking the Test View open the page successfully and show me the content in test.html page. Currently Airflow displays the landing page on the url http://localhost:8080/admin/ with all Dags listed. My requirement is to show this test.html page as the landing page/home page. The structure of is as follows: -AIRFLOW_HOME/plugins/templates/test_plugin/test.html -AIRFLOW_HOME/plugins/test