jinja2

Call a constructed variable name in Jinja2 template?

余生颓废 提交于 2019-12-12 05:07:39
问题 Is there a way in Jinja2 to construct a variable name and then call it? I want to do something like this: {% for type in ('Students', 'Faculty', 'Groups') %} {% set import_name = 'latest_' + type|lower + '_import' %} {{ type }}: {{ import_name.created_at }} {% endfor %} I would expect the output to be something like this: Students: 5/26/2016 Faculty: 5/25/2016 Groups: 5/25/2016 I have the variables latest_students_import, latest_faculty_import, and latest_groups_import set in the template

Ansible remove blank lines from list

别来无恙 提交于 2019-12-12 04:59:49
问题 So I've got a playbook that retrieves the members of an AD group and gives me a list of their user IDs like this: tasks: - name: Get group members set_fact: member: "{{ item }}" register: members with_ldap: - context: group_members - Jira_Administrators_GG - name: Get userids set_fact: userid: "{{ lookup('ldap', '{{ item.item }}', context='users') }}" register: userids with_items: "{{ members.results }}" - name: Create list of userids set_fact: userid_list: "{{ userids.results | map(attribute

How to compared a nested pillar key value in an if statement in jinja2 for saltstack

泄露秘密 提交于 2019-12-12 04:43:29
问题 I am working on a saltstack state with some salt wrapped in jinja2. When I attempt to compare a value from a pillar using jinja2 it appears argument evaluates to nothing. If I query the value using salt cli, it returns the expected value. I expect I am referencing the value incorrectly in the if statement with jinja2. Here is all the needed info to understand and look at this problem: Salt Master id is salt-dev Salt Minion id is on same instance and is salt-dev Here is the pillar top file:

Reference user supplied file with Flask app

我怕爱的太早我们不能终老 提交于 2019-12-12 04:34:09
问题 I am new to Flask and web applications in general. I have images that could be located in different locations: -directory1 -image1 -directory2 -subdirectory -image2 -directory3 -flask_app -app.py -static The purpose of the app is to dynamically provide access to the content in other directories which is not static and subject to change for each user. The content cannot be moved or modified. How do I display images from other directories within the app without moving or modifying them based on

TemplateSyntaxError: unexpected char u'\\' at 205 Airflow Macros

和自甴很熟 提交于 2019-12-12 04:19:31
问题 I am getting the following error : File "<unknown>", line 1, in template TemplateSyntaxError: unexpected char u'\\' at 205 When I include this in my code: '{{ macros.ds_format(macros.ds_add(ds, -13), "%Y-%m-%d", "%Y%m%d") }}' I re-typed it in vim in case it was an error with encoding, but still no luck! 来源: https://stackoverflow.com/questions/44190948/templatesyntaxerror-unexpected-char-u-at-205-airflow-macros

Displaying jinja2 form fields based on attribute value

萝らか妹 提交于 2019-12-12 02:54:56
问题 I'm working on a flask app and using flask-wtf to help manage my forms. There are 2 ways to register on my site - Either with or without an email token. If the email has been confirmed the user gets an email containing: http://127.0.0.1:5000/register/ImNsdWVtYXJpbmUzQG1haWxpbmF0b3IuY29tIg.Ca9oUQ.bRJmGYQ1wNqfcQFx1pYyoCEy2oM Otherwise on the site itself the user could click on: http://127.0.0.1:5000/register The following code can handle both cases: @blueprint.route("/register/", defaults={

AttributeError: 'function' object has no attribute 'user_id'

删除回忆录丶 提交于 2019-12-12 02:27:22
问题 I'm using GAE (in Python) to make a web app, but I have been bumping into some problems with inputting a form (name, class year, bio) into the datastore. This actually used to work before, but not anymore; I'm not too sure what event went wrong here. Here are my controller and template. The error I've been getting is: File "/base/data/home/apps/p~clubs-cs50/1.389022909265479577/main.py", line 136, in post identity=user.user_id(), AttributeError: 'function' object has no attribute 'user_id'

how to display parent entity while looping through child entities in Jinja2 template

折月煮酒 提交于 2019-12-12 02:12:25
问题 How to use this solution https://stackoverflow.com/a/10067749/604240 in jinja 2 template? 回答1: I agree my question was due to lack of knowledge than problem. Eventually I figured it out how to achieve it. Basically I didn't know how to link loop from python code to query so it's available to Jinja2 template. Although correct solution might be to use map() with callback function https://developers.google.com/appengine/docs/python/ndb/queryclass#Query_map but I am using temporary solution which

pyramid_jinja2: ImportError: cannot import name Environment

[亡魂溺海] 提交于 2019-12-12 01:58:23
问题 I'm going through the tutorial for the Pyramid framework and I'm currently stuck at the one that teaches the use of Jinja2 as the templating engine.. It seems that when I run the test using nosetests , I get this odd ImportError stating that the name Environment couldn't be imported from the Jinja2 module. Funny thing is, when I pserve the site, it works just fine. It seems like this error will only occur during the test...I am currently working off a virtualenv using Ubuntu 14.04. Any

Variable in Jinja2 For Loop

核能气质少年 提交于 2019-12-12 01:56:49
问题 We're trying to come up with a way to use ansible facts within jinja2 For Loops. For example, I want to get all servers that belong to my memcached group as well as a group based on release (something like tag_release_dev or tag_release_prod ). When I try to use {{ tt_release }} within the For Loop it evaluates {{ tt_release }} rather than the value of the variable. Is there a way to use a variable within the loop definition? {% for host in groups["tag_function_mem"] | intersect(groups["tag