jinja2

How to select the first item from a list [duplicate]

耗尽温柔 提交于 2019-12-25 07:08:29
问题 This question already has answers here : Django Templating: how to access properties of the first item in a list (3 answers) Closed 5 years ago . I have the following for loop that spits out all photos in a list: {% if photos %} {% for photo in photos %} {% thumbnail photo.photo "100x100" crop="center" as im %} <img src="{{ im.url }}" alt="User's photos" data-ajax="{% url 'photo_increase_view' pk=photo.id %}"/> {% endthumbnail %} {% endfor %} {% endif %} How can I just select and display the

How to select the first item from a list [duplicate]

感情迁移 提交于 2019-12-25 07:07:16
问题 This question already has answers here : Django Templating: how to access properties of the first item in a list (3 answers) Closed 5 years ago . I have the following for loop that spits out all photos in a list: {% if photos %} {% for photo in photos %} {% thumbnail photo.photo "100x100" crop="center" as im %} <img src="{{ im.url }}" alt="User's photos" data-ajax="{% url 'photo_increase_view' pk=photo.id %}"/> {% endthumbnail %} {% endfor %} {% endif %} How can I just select and display the

Creating a comma separated string from a dictionary in Ansible

佐手、 提交于 2019-12-24 18:23:44
问题 I want to write an Ansible role to be able to alter a given Kafka topic. I am using a dictionary of key/value pairs. The command module is then used to execute a Kafka script that take a string of comma separated values. For instance, use app_kafka_topic list: --- app_kafka_topic: cleanup.policy : - "delete" retention.ms : - "146800000" partitions : - "6" replication-factor : - "2" and create the string : "cleanup.policy=delete,retention.ms=146800000,partitions=6,replication-factor=2" This is

SSL issues with jinja HTTPS load balancer - Google Cloud

梦想的初衷 提交于 2019-12-24 16:30:42
问题 I have been able to deploy this load balancer as a HTTP load balancer, and am now trying to deploy this as a HTTPS load balancer. I am attempting this with .JUNJA and .YAML on Google Cloud. I keep getting the error: Invalid value for field 'resource.sslCertificates[0]': 'www.example.com'. The\\ URL is malformed. resources: - name: web-lb-hc #Create a health check for the backend type: compute.v1.httpsHealthCheck properties: port: 443 requestPath: / - name: web-url-map #Required to map url to

Get minions IP inside a salt template filtered by grains

我的梦境 提交于 2019-12-24 13:26:17
问题 I found this answer here that tells how to get the IP of another minions inside a template but i can't get host.fqdn or host.ip . When I use host I get the full domain name and not the IP. When I ran it on console it gets the ips, but inside the template it does return a str object Unable to manage file: Jinja variable 'str object' has no attribute 'fqdn' I tried this one here but this one didn't even show a result. I want to be able to build a hosts file. Each minion have some roles set as

Jinja variable is undefined

岁酱吖の 提交于 2019-12-24 12:05:53
问题 I'm trying to build the hosts file on my servers using salt. In some of the servers, the eth0 network interface has the inet set and in some others is the bond0 interface. In the init.sls i have: /etc/hosts: file.managed: - source: salt://configs/etc/hosts/hostsfile - user: root - group: root - mode: 644 - template: jinja - context: {% for host, interface in salt['mine.get']('*', 'network.interfaces').items() %} {% if interface['bond0'].has_key('inet') %} ip: {{ salt['network.interfaces']()[

How do I create a jinja2 filter and use it within pylons?

时间秒杀一切 提交于 2019-12-24 11:11:45
问题 Am going around the houses trying to find a way to implement a simple filter. I want to create the equivalent of some Smarty "tags" to make porting easier, notably {mail_to} http://www.smarty.net/manual/en/language.function.mailto.php I seem to be going around in circles between the jinga2 docs http://jinja.pocoo.org/2/documentation/extensions#module-jinja2.ext and the webhelpers http://pylonshq.com/docs/en/0.9.7/modules/templating/ What I'm expecting to write is something like {% mail_to

Attribute error using Jinja2 grouby filter

╄→гoц情女王★ 提交于 2019-12-24 11:09:43
问题 Trying to get the groupby filter to work I'm getting an Atribute error. My groupby code looks like: {% for year, year_purchases in purchases|groupby('PurchaseDate.year')|reverse %} <h2 class="year">{{ year }}</h2> {% for ... %} {% endfor %} {% endfor %} Where purchases is a list of PurchaseEntity: class PurchaseEntity: def __init__(self): self.PurchaseDate = '' self.Orders = [] def load_from_query(self,result): self.PurchaseDate = result.PurchaseDate I'm getting the following error:

Jinja2 PackageLoader on google app engine

老子叫甜甜 提交于 2019-12-24 10:38:57
问题 I want to use jinja2.PackageLoader on Google App engine, but that appears to depend on pkg_resources, which wasn't added until Python 2.6. Am I Out of luck? 回答1: You should be able to include pkg_resources.py in your application directory (or elsewhere in sys.path if you're modifying it in your scripts); according to Guido it should work since App Engine 1.2.1. 来源: https://stackoverflow.com/questions/3809304/jinja2-packageloader-on-google-app-engine

Looping over a list in a Jinja2 template

一个人想着一个人 提交于 2019-12-24 10:33:06
问题 Im trying to make a simple blog website with the Flask framework. Each entry in my blog has a title, text and comments. the title and text are stored in a table named entries and the comments in a table named comments that links the comments to the corresponding entry with a foreign key. The problem I have now is that I want to display the comments in my html file. To do is I want to call a python function named show_comments in my html file while I'm in a for loop. The python function looks