title: Mako avoid python imports
body: <p>I am trying to create a template inheriting from another one using methods like <code>url_for</code>. If I delete <code>import</code> statement I get an error:</p>
  
  <pre><code>TypeError
  TypeError: 'Undefined' object is not callable
  </code></pre>
  
  <p>Can I get rid of imports below?</p>
  
  <p>main.html file:</p>
  
  <pre><code>&lt;!doctype html&gt;
  &lt;%!
      from flask.helpers import url_for
      from flask.globals import request
  %&gt;
  &lt;html lang=en&gt;
  
  &lt;head&gt;
      &lt;%block name="additional_scripts"/&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
  &lt;/body&gt;
  &lt;h1&gt;Presence analyzer&lt;/h1&gt;
      &lt;ul&gt;
          % for key, template in templates.items():
              &lt;li
                  % if request.path == '/statistics/{}/'.format(template['name']):
                      id="selected"
                  % endif
              &gt;
                  &lt;a href="${url_for('statistics_view', chosen=template['name'])}"&gt;${template['description']}&lt;/a&gt;
              &lt;/li&gt;
          % endfor
      &lt;/ul&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>The inheriting file:</p>
  
  <pre><code>&lt;%inherit file="main.html"/&gt;
  
  &lt;%!
      from flask.helpers import url_for
  %&gt;
  
  &lt;%block name="additional_scripts"&gt;
      &lt;script type="text/javascript"&gt;
          google.load("visualization", "1", {packages:["corechart", "timeline"], 'language': 'pl'});
      &lt;/script&gt;
      &lt;script src="${url_for('static', filename='js/presence_weekday.js')}"&gt;&lt;/script&gt;
  &lt;/%block&gt;
  </code></pre>
  
  <p>Calling view method:</p>
  
  <pre><code>@app.route('/statistics/&lt;chosen&gt;/')
  def statistics_view(chosen):
      try:
          return LOOKUP.get_template(templates[chosen]['template']).render(templates=templates)
      except KeyError:
          abort(404)
  </code></pre>
  
  <p>And <code>main.py</code> file where app is created:</p>
  
  <pre><code>import os
  
  from flask import Flask
  from mako.lookup import TemplateLookup
  
  app = Flask(__name__)  # pylint: disable=invalid-name
  LOOKUP = TemplateLookup(directories=[os.path.join(os.path.dirname(os.path.realpath(__file__)),
                                                    'templates')])
  </code></pre>