I'm building an admin for Flask and SQLAlchemy, and I want to pass the html for the different inputs to my view using render_template. The templating framework seems to escape the html automatically, so all <"'> are converted to html entities. How can I disable that so that the html renders correctly?
...
I'am new to the Jinja2 template engine. Is there something like the view-helpers from Zend Framework? Can i create simple functions and reuse them all over all my template-files?
Something like this?
#somewhere in my python code:
def nice_demo_function(message):
""""return a simple message"""
return message
So i can to use th...
I've got a dashboard that namespaces the context for each dashboard item. Is there a quick way I can set all the values of a dictionary to the keys in a template?
I want to reuse templates and not always namespace my variables.
My context can be simplified to look something like this:
{
"business": {"businesses": [], "new_promotion...
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/...
If I return a Jinja2 template like so:
return render_response('home.htm', **context)
How do then get a list of the variables in context from within the template?
...
I'm very new to jinja2 and the use of templates in general so I was wondering if there's an easy way to load an external javascript. I was thinking of using:
{% block javascript %}
<SCRIPT SRC="myscript.js"></SCRIPT>
{% endblock %}
But I can't help to ask:
Is there a way of loading this script directly from within a template dire...
I didn't find a good comparison of jinja2 and Mako. What would you use for what tasks ?
I personnaly was satisfied by mako (in a pylons web app context) but am curious to know if jinja2 has some nice features/improvements that mako doesn't ? -or maybe downsides ?-
...
I have two for loops, both alike in dignity. I'd like to have a counter incremented during each inner iteration.
For example, consider this template:
from jinja2 import Template
print Template("""
{% set count = 0 -%}
{% for i in 'a', 'b', 'c' -%}
{% for j in 'x', 'y', 'z' -%}
i={{i}}, j={{j}}, count={{count}}
{% set count =...
I'm integrating jinja2 to pylons, I see in the document page there is:
from jinja2 import Environment, PackageLoader
config['pylons.app_globals'].jinja_env = Environment(
loader=PackageLoader('yourapplication', 'templates')
)
My question is: what should I use for yourapplication? Suppose my application is 'test', what should I wri...
Recently I switched my templating engine from default to Jinja2/Coffin. Everything works just fine but I'm having troubles trying to use Django/Jinja2 django-paging (http://linux.softpedia.com/get/Internet/HTTP-WWW-/django-paging-58496.shtml) extension in my project.
There is an example how to use this extension with Jinja:
{% with pag...
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?
...
I have String which contains some HTML and I'd like to escape it. After that I need to convert all /n into new lines with:
@environmentfilter
def filter_newLine(env, value):
result = value.replace('\n', '<br/>')
if env.autoescape:
result = Markup(result)
return result
I use the the filter {{status|e|filter_newLine}...
Hi I've been trying to create an extension for jinja2 that would join multiple items with a separator, while skipping items (template fragments) that evaluate to whitespace.
There are several of those fragments and you never know in advance which ones will be non-empty and which ones will.
Sounds like a trivial task, but I had real har...
Converting from Django, I'm used to doing something like this:
{% if not var1 %} {% endif %}
and having it work if I didn't put var1 into the context. Jinja2 gives me an undefined error. Is there an easy way to say {% if var1 == None %} or similar?
...
I am a very young programmer and I am trying to do something in Python but I'm stuck. I have a list of users in Couchdb (using python couchdb library & Flask framework) who have a username (which is the _id) and email. I want to use the list of email addresses in a select box in a jinja2 template.
My first problem is how to access the e...
Is there a method for jinja2 to raise an exception when we pass a variable that is not present in the template?
PS: This is different(or opposite) from raising an exception when a variable is present in the template but it is not passed. For this I use "undefined=StrictUndefined"
...
I'm trying to use the jinja2 templating langauge to return the last n(say, 5) posts in my posts list:
{% for recent in site.posts|reverse|slice(5) %}
{% for post in recent %}
<li> <a href="/{{ post.url }}">{{ post.title }}</a></li>
{% endfor %}
{% endfor %}
This is returning the whole list though. How do you strip the...
I'm making a simple script that works on Jinja2 templates. Right now it's just reading files in from disk manually, i.e. no Jinja Loaders. I have 2 strings (A and B), representing 2 templates. I want to make one template (B) inherit from the other (A), i.e. I have {% block body %}{% endblock %} in A, and I want to make the body block be ...