title: How to make dict always available to a particular template with Django/Jinja2?
body: <p>I have a template (using jinja2) that is used in lots of views (via {% include %} statements). The template will always require (amongst other data that changes, and will be passed in via the context) a dict, that is a constant. It would be cumbersome to add the dict to the context in every view that will potentially use the template. </p>
  
  <p>I could add the dict as a global variable in the jinja2 env.globals, but that doesn’t seem like a particularly good idea either. It is only needed in one template in one app, not the entire project. </p>
  
  <p>The Jinja2 documentation mentions template globals specific to a particular template, but I can’t figure out how to implement this with Django. </p>
  
  <p>Any help appreciated, thanks :)</p>
  
  <p>EDIT: Some additional context.</p>
  
  <p>The template provides some  information to be used in lots of other html documents (via the include tag). The positions of the lines and polygons are the same, but the colours are different. I don’t particularly want to hard-code all of the <code>x1=”20” x2=”30”</code> etc, so it would be useful to have all of this stored in a dict, and do something like the following:</p>
  
  <pre><code>{# Template to be included #}
  &lt;svg class="a" width="200px" height="200px" viewBox="0 0 100 100" preserveAspectRatio="none"&gt;
  {% for i in range(10) %}        
      &lt;line {{dict_always_available[i]}} class="{{info_passed_in_context[i]}}"&gt;&lt;/line&gt;
  {% endfor %}
  &lt;/svg&gt;
  </code></pre>
  
  <p>I don't want to have to pass dict_always_available into the context in every view that will potentially (but not necessarily) need it.</p>