title: render_template HTML renders but variables not evaluated
body: <p>I am trying to build an "enterprise grade" version of a flask app so am using blueprints and a fancy directory structure. I have a "toy" version of this app where everything is in a very flat directory structure with no blueprints and it works. </p>
  
  <p>I have a route program that calcs some variables then passes them to <code>render_template</code> to generate html. The html displays in the browser but all of the variables appear to be set to <code>NONE</code>. </p>
  
  <p>My app uses blueprints and SQLite3.</p>
  
  <p>I have tried multiple things to isolate the error.</p>
  
  <ol>
  <li><p>Make a textual change to html template to ensure the right template is being picked up. It is.</p></li>
  <li><p>Pass trivial string variable to html template and see if they show up, they don't.</p></li>
  <li><p>View source of rendered html, there is <em>nothing</em> where the flask variable names {{ x }} occur in the html template, including the {{ x }} text itself. So it appears the value None has been been used.</p></li>
  <li><p>Test the code leading up to the <code>render_template</code>, it works perfectly.</p></li>
  </ol>
  
  <p>My directory structure is: -</p>
  
  <pre><code>\myapp
    app.py
    \app
      __init__.py
      \main
        __init__.py
        routes.py
        ...
      \meta
        __init__.py
        routes.py
        ...
      \templates
        ...
        base.html
        index.html
  </code></pre>
  
  <p>The code in \meta\routes.py (which corresponds to the meta blueprint) works down to and including <code>entitys = stmt.fetchall()</code> and is: -</p>
  
  <pre><code>from flask import Flask, render_template, request
  import sqlite3 as sql
  from app.meta import bp
  from app import Config
  
  config = Config()
  metafile = os.path.join(config.META_DIR, config.META_MS, config.META_DB)
  
  @bp.route('/', methods=['GET', 'POST'])
  @bp.route('/index', methods=['GET', 'POST'])
  def index():
  
      meta = sql.connect(metafile)
  
      stmt = meta.cursor()
      stmt.execute("SELECT * FROM [meta.Entity]")
  
      entitys = stmt.fetchall()
      return render_template("index.html", entitys = entitys)
  </code></pre>
  
  <p>In case it is relevant here is \meta\__init__.py: -</p>
  
  <pre><code>from flask import Blueprint
  
  bp = Blueprint('meta', __name__)
  </code></pre>
  
  <p>The template html is as follows. The base.html is: -</p>
  
  <pre><code>&lt;!doctype html&gt;
  &lt;html&gt;
      &lt;head&gt;
          {% if title %}
              &lt;title&gt;{{ title }} - Metapplica&lt;/title&gt;
          {% else %}
              &lt;title&gt;Metapplica&lt;/title&gt;
          {% endif %}
          &lt;meta name="viewport" content="width=device-width, initial-scale=1"&gt;
          &lt;link rel="stylesheet" href="{{ url_for('static', filename = 'w3.css') }}"&gt;
          &lt;link rel="stylesheet" href="{{ url_for('static', filename = 'style.css') }}"&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;div&gt;
              &lt;a href="{{ url_for('main.index') }}"&gt;Home&lt;/a&gt;
          &lt;/div&gt;
          &lt;hr&gt;
          {% with messages = get_flashed_messages() %}
              {% if messages %}
                  &lt;ul&gt;
                      {% for message in messages %}
                          &lt;li&gt;{{ message }}&lt;/li&gt;
                      {% endfor %}
                  &lt;/ul&gt;
              {% endif %}
          {% endwith %}
          {% block content %}{% endblock %}
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>and index.html is: -</p>
  
  <pre><code>{% extends "base.html" %}
  
  {% block content %}
      &lt;h2&gt;Entities&lt;/h2&gt;
      &lt;table border = 1&gt;
          &lt;thead&gt;
              &lt;td&gt;Entity&lt;/td&gt;
              &lt;td&gt;Action&lt;/td&gt;
          &lt;/thead&gt;
  
          {% for entity in entitys %}
              &lt;tr&gt;
                  &lt;td&gt;{{ entity["Name"] }}&lt;/td&gt;
                  &lt;td&gt;
                      &lt;a href="{{url_for("entity_list", entity=entity["EntityId"])}}"&gt;List&lt;/a&gt;
                      &lt;a href="{{url_for("entity_add", entity=entity["EntityId"])}}"&gt;Add&lt;/a&gt;
                  &lt;/td&gt;   
              &lt;/tr&gt;
          {% endfor %}
      &lt;/table&gt;
  {% endblock %}
  </code></pre>
  
  <p>Finally the rendered html is this: -</p>
  
  <pre><code>&lt;!doctype html&gt;
  &lt;html&gt;
      &lt;head&gt;
  
              &lt;title&gt;Home - Metapplica&lt;/title&gt;
  
          &lt;meta name="viewport" content="width=device-width, initial-scale=1"&gt;
          &lt;link rel="stylesheet" href="/static/w3.css"&gt;
          &lt;link rel="stylesheet" href="/static/style.css"&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;div&gt;
              &lt;a href="/index"&gt;Home&lt;/a&gt;
          &lt;/div&gt;
          &lt;hr&gt;
  
  
  
  
      &lt;h2&gt;Entities &lt;/h2&gt;
      &lt;table border = 1&gt;
          &lt;thead&gt;
              &lt;td&gt;Entity&lt;/td&gt;
              &lt;td&gt;Action&lt;/td&gt;
          &lt;/thead&gt;
  
  
      &lt;/table&gt;
  
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>In response to @Tobin's comment I have included the code that (should) be registering the blueprint. I use an application factory.</p>
  
  <p>Here is app\__init__()</p>
  
  <pre><code>import logging
  from logging.handlers import SMTPHandler, RotatingFileHandler
  import os
  from flask import Flask, session, redirect, url_for, escape, request, current_app
  from config import Config
  
  def create_app(config_class=Config):
      app = Flask(__name__)
      app.config.from_object(config_class)
  
  #   Register blueprints
      from app.errors import bp as errors_bp
      app.register_blueprint(errors_bp, url_prefix='/err')
  
      from app.auth import bp as auth_bp
      app.register_blueprint(auth_bp, url_prefix='/auth')
  
      from app.meta import bp as meta_bp
      app.register_blueprint(meta_bp, url_prefix='/meta')
  
      from app.main import bp as main_bp
      app.register_blueprint(main_bp)
  
      return app
  </code></pre>
  
  <p>and here is the code that calls it: -</p>
  
  <pre><code>from app import create_app
  
  app = create_app()
  </code></pre>
  
  <p>I suspect that somehow when Flask renders the html template the passed variables are not available to the "flask engine" which is pointing somewhere else. </p>
  
  <p>Nothing fails and there are no error messages.</p>
  
  <p>What am I doing wrong?</p>