jinja2

Jinja doesn't render anything when extending layout template

陌路散爱 提交于 2019-12-20 05:22:15
问题 I'm trying to display data on a page, but the page is completely empty. I know the database has data in it, and I know the query_db function returns the correct results, but I can't figure out why the data isn't being rendered by Jinja. What is causing this problem? @app.route('/toto') def toto(): entries = query_db("select col1,col2 from toto where col1 = 'grand test'") return render_template('show_results.html', entries = entries) show_results.html : {% extends "layout.html" %} {% block

3,Flask 中的模板语言 Jinja2 及 render_template 的深度用法

那年仲夏 提交于 2019-12-20 05:06:53
Flask中默认的模板语言是Jinja2 现在我们来一步一步的学习一下 Jinja2 捎带手把 render_template 中留下的疑问解决一下 首先我们要在后端定义几个字符串,用于传递到前端 STUDENT = {'name': 'Old', 'age': 38, 'gender': '中'}, STUDENT_LIST = [ {'name': 'Old', 'age': 38, 'gender': '中'}, {'name': 'Boy', 'age': 73, 'gender': '男'}, {'name': 'EDU', 'age': 84, 'gender': '女'} ] STUDENT_DICT = { 1: {'name': 'Old', 'age': 38, 'gender': '中'}, 2: {'name': 'Boy', 'age': 73, 'gender': '男'}, 3: {'name': 'EDU', 'age': 84, 'gender': '女'}, } 但是前提我们要知道Jinja2模板中的流程控制: I. Jinja2模板语言中的 for {% for foo in g %} {% endfor %} II. Jinja2模板语言中的 if {% if g %} {% elif g %} {% else %} {% endif %}

What does this error message mean in appengine?

最后都变了- 提交于 2019-12-20 04:23:25
问题 Search failed Traceback (most recent call last): File "/base/data/home/apps/s~montaoproject/2013e.368508855356793432/search_demo.py", line 87, in find_documents return index.search(query) File "/python27_runtime/python27_lib/versions/1/google/appengine/api/search/search.py", line 2732, in search _CheckStatus(response.status()) File "/python27_runtime/python27_lib/versions/1/google/appengine/api/search/search.py", line 413, in _CheckStatus raise _ERROR_MAP[status.code()](status.error_detail())

Syntax error in jinja 2 library

梦想的初衷 提交于 2019-12-20 04:19:07
问题 For running the IPython Notebook on a suse Linux server, I needed to install the jinja2 library: pip-3.2 install jinja2 Installation printed a syntax error but also said "installation successful". On import, I get the following error: In [1]: import jinja2 File "/usr/local/lib/python3.2/site-packages/jinja2/environment.py", line 639 u'\xff\xff\xff\xff'.encode('iso-8859-15') ^ SyntaxError: invalid syntax Bug in the jinja2 package? Any way for me to fix this? 回答1: Jinja2 only supports Python 3

Symbol | in view for Flask tutorial

与世无争的帅哥 提交于 2019-12-20 04:05:18
问题 I'm doing a tutorial for the Flask framework at http://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-iii-web-forms In this very chapter I've found a piece of code that I didn't understand. It is: |{% for pr in providers %} <a href="javascript:set_openid('{{pr.url}}', '{{pr.name}}');">{{pr.name}}</a> | {% endfor %} Why do we need the symbol | there? 回答1: This pipe is simply adding the | between providers, as seen in the screenshot. Notice the symbol between "Google" and "Yahoo"

Render JSON without replacing characters in Jinja [duplicate]

♀尐吖头ヾ 提交于 2019-12-20 03:30:20
问题 This question already has answers here : JavaScript raises SyntaxError with data rendered in Jinja template (2 answers) Closed 3 years ago . I have some Python data that will be sent to a JavaScript chart. I dump it to JSON and pass it to the template. When I render the data, it contains html entities ( " ) instead of quotes, which isn't valid. How do I correctly pass the JSON data from Python to JavaScript? pieData = [{'color': '#400068', 'name': 'xyz', 'value': 10}, {'color': '#4a8624',

How does the 'with' statement work in Flask (Jinja2)?

旧城冷巷雨未停 提交于 2019-12-19 18:54:25
问题 In Python you can use the with statement like this (source): class controlled_execution: def __enter__(self): # set things up return thing def __exit__(self, type, value, traceback): # tear things down with controlled_execution() as thing: # some code In Flask/Jinja2, the standard procedure for using flash messages is the following (source): {% with messages = get_flashed_messages() %} {% if messages %} {% for message in messages %} <!-- do stuff with `message` --> {% endfor %} {% endif %} {%

Do statement not working in jinja

这一生的挚爱 提交于 2019-12-19 09:26:55
问题 I'm altering an existing web interface to view ROBOT doc libraries, which uses a mixture of jinja (Python inside HTML) and HTML. I have never worked with jinja or HTML before and am having issues getting even a simple test case to work. When the browser loads the docs, I want our project's directory structure for the docs to be preserved to make finding things easier, and so I want to use jinja to create the dir structure. Here is a snippet of the code I'm working with: {% extends "base.html"

newline and dash not working correctly in jinja

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-19 07:53:43
问题 How could I generate the expected output ? Thanks jinja template {%- for field in fields -%} - name: {{field}} type: string {%- endfor -%} output - name: operating revenue type: string- name: gross operating profit type: string- expected output - name: operating revenue type: string - name: gross operating profit type: string code from jinja2 import Template fields = ["operating revenue", "gross operating profit", "EBITDA", "operating profit after depreciation", "EBIT", "date"] template_file

How to convert a dictionary of dictionaries into a list of dictionaries in a Ansible vars file?

泄露秘密 提交于 2019-12-19 05:45:10
问题 Within an Ansible vars file, I want to convert a dict of dicts into a list of dicts that I can pass to an external role from Ansible Galaxy. Input: postgres_users: dc1: name: user_dc1 password: pass_dc1 dc2: name: user_dc2 password: pass_dc2 dc3: name: user_dc3 password: pass_dc3 Desired output: postgres_users: - name: user_dc1 password: pass_dc1 - name: user_dc2 password: pass_dc2 - name: user_dc3 password: pass_dc3 Is there a simple way to do this within an Ansible vars file? 回答1: {{