jinja2

How to make a for loop in Jinja?

烂漫一生 提交于 2019-12-23 06:56:36
问题 I want to make a for-loop that goes from 0 to 10 in Jinja . How do I do it? All I know to do is the advanced for, but this does not help me now. 回答1: do something like this... {% for i in range(11) %} {{ i }} {% endfor %} Edited the endfor. Hope this helps! 来源: https://stackoverflow.com/questions/29706099/how-to-make-a-for-loop-in-jinja

Jinja2 returns “None” string for Google App Engine models

吃可爱长大的小学妹 提交于 2019-12-22 18:27:28
问题 Google App Engine models, likeso: from google.appengine.ext.db import Model class M(Model): name = db.StringProperty() Then in a Jinja2 template called from a Django view with an in instance of M passed in as m : The name of this M is {{ m.name }}. When m is initialized without name being set, the following is printed: The name of this M is None. The preferable and expected output (and the output when using Django templates) would be/is: The name of this M is . Do you know why this is

Jinja not rendering css/images in sub-directories

核能气质少年 提交于 2019-12-22 14:48:10
问题 I'm using Jinja2 and GAE, and I'm using a helper function to render HTML files. When I try to render a HTML file that is nested within a subdirectory (Gamification), Jinja doesn't seem to be pulling out the CSS and images files. Does anyone know what I should do? My current YAML structure is as follows handlers: - url: /favicon\.ico static_files: favicon.ico upload: favicon\.ico - url: .* script: main.app libraries: - name: webapp2 version: "2.5.1" - name: jinja2 version: latest My current

Flask blueprint looks for static file in blueprint instead of root directory

旧时模样 提交于 2019-12-22 09:30:04
问题 The blueprint I have should look for static files in the root directory but it isn't. Say I have a blueprint named 'frontend'. 'frontend' only has template_folder='frontend' passed in. Even if I put the static files under /app/frontend/static/file.css, it doesn't find it. Neither does it find it in /app/static/file.css. The console webserver says '404' for every css or js static file every time. But I do have this showing when I print out url_maps: <Rule '/static/<filename>' (HEAD, OPTIONS,

Querying for specific articles (via tag/category) in Pelican themes

末鹿安然 提交于 2019-12-22 09:00:03
问题 Is it possible to set query parameters via jinja in Pelican template files? index.html {% if articles %} {% for article in articles_page.object_list if article.category == 'article' %} #stuff {% endfor %} {% endif %} This will return articles in the article category, but only if they happen to be in the articles already queried for. The desirable setup would be to grab x articles in y category (or with y tag) - is that possible? 回答1: This code snippet works for me to bring back a list of all

Rendering Jinja template in Flask following ajax response

自古美人都是妖i 提交于 2019-12-22 08:29:10
问题 This is my first dive into Flask + Jinja, but I've used HandlebarsJS a lot in the past, so I know this is possible but I'm not sure how to pull this off with Flask: I'm building an app: a user enters a string, which is processed via python script, and the result is ajax'd back to the client/Jinja template. I can output the result using $("body").append(response) but this would mean I need to write some nasty html within the append. Instead, I'd like to render another template once the result

problem with jinja2 autoescape in google app engine webapp

狂风中的少年 提交于 2019-12-22 06:55:44
问题 I decided to install jinja2 to use with my webapp application in order to support the autoescape functionality. So I installed jinja2 into python 2.5 and created a symlink within my project to point to that directory. It's mostly working fine. EXCEPT, when I actually try to use the {% autoescape true %} tag, I get the message: File "/Users/me/project/templates/_base.html", line 1, in template {% autoescape true %} TemplateSyntaxError: Encountered unknown tag 'autoescape'. I'm using the tags

Babel doesn't recognize jinja2 extraction method for language support

╄→гoц情女王★ 提交于 2019-12-22 05:58:12
问题 I'm adding language translation support to my project. The code is on Python and has jinja2 in the html files, and Javascript. I'm trying to use Babel to do the translation, but it doesn't recognize the extraction method of jinja2. Maybe I'm using an incorrect name for it. This is my ini file: # Extraction from Python source files [python: **.py] # Extraction from Jinja2 template files [jinja2: **.html] # Extraction from JavaScript files [javascript: **.js] extract_messages = $._, jQuery._

Django 1.8 with Jinja2: Contrib app Admin not working

自闭症网瘾萝莉.ら 提交于 2019-12-22 05:25:31
问题 I upgraded to a fresh install of Django 1.8 and began using Jinja2 as it said that it was supported now and Jinja2 has some features I could use in my project. After finishing adapting the templates for my app to Jinja2 and taking advantage of the new features now available, I discovered that the contrib app Admin no longer works. "TemplateDoesNotExist at /admin/login/" So it turns out that contrib app Admin only has templates made for DjangoTemplates and not for Jinja2. I did the naive thing

Sum elements of the list in Jinja 2

你。 提交于 2019-12-22 05:03:03
问题 I have list in Jinja2 that contain dicts in itself. Something like items = [{'name':'name1', 'points':5}, {'name':'name2', 'points':7}, {'name':'name3', 'points':2}, {'name':'name4', 'points':11}] What I need is to get sum of all points and to print it somewhere later. Currently what I got is: {% set points = 0 -%} {% for single_item in items -%} {% set points = points + single_item["points"] -%} {{points}} {% endfor %} {{ points }} Result is: 5 12 14 25 0 Is there any way that I can get that