jinja2

How to debug Jinja2 template ?

I am using jinja2 template system into django. It is really fast and I like it a lot. Nevertheless, I have some problem to debug templates : If I make some errors into a template (bad tag, bad filtername, bad end of block...), I do not have at all information about this error. For example, In a django view, I write this : from jinja2 i...

String concatenation in Jinja

I just want to loop through an existing list and make a comma delimited string out of it. Something like this: my_string = 'stuff, stuff, stuff, stuff' I already know about loop.last, I just need to know how to make the third line in my code below WORK. {% set my_string = '' %} {% for stuff in stuffs %} {% set my_string = my_string + s...

Jinja-like for Pdf in Python

I am looking for the best accurate tool for PDF in Python that works like Jinja do for HTML. What are your suggestions? ...

Getting translation strings for jinja2 templates integrated with django 1.x?

I can use jinj2 templates with django via render_to_response defined as below from django.conf import settings from django.core.exceptions import ImproperlyConfigured from django.http import HttpResponse from django.template import TemplateDoesNotExist, Context from django.utils import translation from itertools import chain from jinja...

In Jinja2, how can I use macros in combination with block tags?

I'm a front end developer, and I've been trying to get a hang on using Jinja2 effectively. I want to tweak a current site so it has multiple base templates using inheritance, it fully uses block tags to substitute content and override it, and uses macros to support passing of arguments. My base template contains this code (edited for si...

Strip whitespace in generated HTML using pure Python code

I am using Jinja2 to generate HTML files which are typically very huge in size. I noticed that the generated HTML had a lot of whitespace. Is there a pure-Python tool that I can use to minimize this HTML? When I say "minimize", I mean remove unnecessary whitespace from the HTML (much like Google does -- look at the source for google.com,...

Does the Jinja2 templating language have the concept of 'here' (current directory)?

Does Jinja2 support template-relative paths e.g. %(here)s/other/template.html, to include other templates relative to the current template's place in the filesystem? ...

Jinja2 in Google App Engine

Hello, I have started using Jinja2 as my templating engine on Google App Engine (in Python). My question is this: Will bytecode caching work in production? It is working very well on the development server, but I read somewhere that bytecode caching depends on the marshal module, which is not supported in App Engine. This answer to a d...

How do I access session data in Jinja2 templates (Bottle framework on app engine)?

Hello! I'm running the micro framework Bottle on Google App Engine. I'm using Jinja2 for my templates. And I'm using Beaker to handle the sessions. I'm still a pretty big Python newbie and am pretty stoked I got this far :) My question is how do I access the session data within the templates? I can get the session data no problem w...

Jinja2 returns "None" string for Google App Engine models

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 ...

How can I modify/merge Jinja2 dictionaries?

I have a Jinja2 dictionary and I want a single expression that modifies it - either by changing its content, or merging with another dictionary. >>> import jinja2 >>> e = jinja2.Environment() Modify a dict: Fails. >>> e.from_string("{{ x[4]=5 }}").render({'x':{1:2,2:3}}) Traceback (most recent call last): File "<stdin>", line 1, in...

Create Jinja2 macros that put content in separate places

I want to create a table of contents and endnotes in a Jinja2 template. How can one accomplish these tasks? For example, I want to have a template as follows: {% block toc %} {# ... the ToC goes here ... #} {% endblock %} {% include "some other file with content.jnj" %} {% block endnotes %} {# ... the endnotes go here ... #} {...

CSS file pathing problem

Hi there, When designing a HTML template in my favorite editor (TextPad at the moment) I can view my code in a browser by pressing F11 or the appropriate toolbar button. I have my common css rules in a separate file so my HTML contains the code: <link rel="stylesheet" href="commoncss.css" type="text/css"> This works when the .css f...

Sharing Jinja2 templates between Pylons and Django applications

I'm writing a couple of Jinja2 templates that basically implement some common grid layouts. I'd like to be able to share this 'library' of templates between a Pylons app and Django app. I've hit a minor stumbling block in that Django's template context is accessible from the "top-level" of the template, whereas Pylons wraps your conte...

Import / include assigned variables in Jinja2

In Jinja2, how can one access assigned variables (i.e. {% set X=Y %}) within files incorporated with include? I'd expect the following to work given two Jinja2 files: A.jinja: Stuff {% include 'B.jinja' -%} B has {{ N }} references B.jinja: {% set N = 12 %} I'd expect that A.jinja, when compiled with Jinja2, would produce the fol...

Multi-part template issue with Jinja2

Hi, When creating templates I typically have 3 separate parts (header, body, footer) which I combine to pass a single string to the web-server (CherryPy in this case). My first approach is as follows... from jinja2 import Environment, FileSystemLoader env = Environment(loader=FileSystemLoader('')) tmpl = env.get_template('Body.html'...

Debug Jinja2 in Google App Engine

When I'm running Jinja2 in Google App Engine, I get useless debugging information. I gather this is because of this item in the FAQ: My tracebacks look weird. What’s happening? If the speedups module is not compiled and you are using a Python installation without ctypes (Python 2.4 without ctypes, Jython or Google’s AppEngine) J...

concat multiple block in jinja2 ?

I use jinja2 for my template engine in python. i would like to join content of multiple block and would like to render it at the end of the template, just before tag. { they are various JavaScript snippets throughout the code in multiple template which i would like to move to the end of the file, how do i do it ? } edit : I would l...

Installing Jinja2 on a server without root access

I am trying to install Jinja2 on a web server. I tried running the command "easy_install Jinja2" as they suggested and got an error: [Errno 13] Permission denied: '/usr/lib/python2.5/site-packages/test-easy-install-15897.write-test' I thought that since this was a permission problem, I tried the same thing with "sudo". I was asked ...

How to make sure a Jinja custom tag only outputs once?

I have a custom tag in Jinja2 that I want to output something only the first time that it is called. So say I have the following template: 1. {% only_once %} 2. {% only_once %} 3. {% only_once %} I want the output to be: 1. "I only get printed once!" 2. 3. I'm guessing the best way to do this is to set a flag in the context of the...