title: Query a template for the variables it needs?
body: <p>I'd like to be able to instantiate a template from a file (presumably using the django.template.loader.get_template(filename) ), and then determine the set of variables that should be defined in whatever context it is passed.</p>
  
  <p>I thought there would be a method on the Template object, but there doesn't seem to be. </p>
  
  <p>I read the docs, and the closest I found was this:</p>
  
  <p><a href="http://docs.djangoproject.com/en/1.0/topics/templates/#using-the-built-in-reference" rel="noreferrer">http://docs.djangoproject.com/en/1.0/topics/templates/#using-the-built-in-reference</a></p>
  
  <p>which suggests going to the admin interface to see all the variables associated with a given view.</p>
  
  <p>I don't want to go through the admin interface because I want to do this programmatically -- I'm trying to write tests.</p>
  
  <p>I'm using Django version (1, 0, 2, 'final', 0)</p>
  
  <p>Updated:</p>
  
  <p>I tried synack's answer and found that (with the replacement of filter_expression.token by filter_expression.var, to get the actual name of the variable without tags and so on) it returned the variables that are defined locally in the template, but did not work for variables that are defined in the parent that it extends. </p>
  
  <p>So for example, suppose I have templates in two files:</p>
  
  <p>toyparent.html:</p>
  
  <pre><code>{%block base_results%}
  Django is {{adjective}}
  {%endblock base_results%}
  </code></pre>
  
  <p>toychild.html:</p>
  
  <pre><code>{% extends "toyparent.html" %}
  
  {%block base_results%}
      {{block.super}}
      I {{verb}} it.
  {%endblock base_results %}
  </code></pre>
  
  <p>And I load the child template:</p>
  
  <pre><code>&gt;&gt;&gt; toy=django.template.loader.get_template('toychild.html')
  </code></pre>
  
  <p>This renders properly:</p>
  
  <pre><code>&gt;&gt;&gt; toy.render(django.template.Context(dict(adjective='cool',verb='heart')))
  u'\n    \nDjango is cool\n\n    I heart it.\n\n'
  </code></pre>
  
  <p>But I can't get the two variables from it:</p>
  
  <pre><code>&gt;&gt;&gt; v=toy.nodelist.get_nodes_by_type(VariableNode)
  &gt;&gt;&gt; for k in v: print k.filter_expression.var
  ...
  block.super
  verb
  </code></pre>