Note that there are some explanatory texts on larger screens.

plurals
  1. POJinja globals in django - using coffin
    primarykey
    data
    text
    <p>I have some helper functions I want to access from my templates, but having trouble accessing these. Using Jinja2 with Coffin (which is great, except I can't seem to access my global functions).</p> <p>I register my objects in jinja.py</p> <pre><code>from coffin.template import Library register = Library() @register.object(name='tester') def tester(): return 'TESTING YAA!!' print (register.jinja2_globals) </code></pre> <p>My template tester.html looks like this:</p> <pre><code>{{ tester() }} </code></pre> <p>But this is what happens:</p> <pre><code>&gt;&gt;&gt; from apps import jinja {'tester': &lt;function tester at 0x3133938&gt;} &gt;&gt;&gt; jinja.tester() 'TESTING YAA!!' </code></pre> <p>Import works fine and the function registers correctly but can't access with render_to_response or render_to_string:</p> <pre><code>&gt;&gt;&gt; from coffin.template.loader import render_to_string as rts &gt;&gt;&gt; rts('tester.html') Traceback (most recent call last): File "&lt;console&gt;", line 1, in &lt;module&gt; File "/pydev/drew/iame/lib/python2.6/site-packages/Coffin-0.3.7.dev-py2.6.egg/coffin/template/loader.py", line 55, in render_to_string return template.render(context_instance) File "/pydev/drew/iame/lib/python2.6/site-packages/Coffin-0.3.7.dev-py2.6.egg/coffin/template/__init__.py", line 56, in render return super(Template, self).render(**context) File "/pydev/drew/iame/lib/python2.6/site-packages/jinja2/environment.py", line 894, in render return self.environment.handle_exception(exc_info, True) File "/pydev/drew/iame/iame_cms/apps/templates/tester.html", line 1, in top-level template code {{ tester() }} UndefinedError: 'tester' is undefined </code></pre> <p>But isn't accessible in my template :(</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload