title: Correct way to include a sidebar across many templates?
body: <p>I'm trying to figure out the best way to include some sidebar code that will be used on almost every one of my templates. For example, my <code>index.html</code> is</p>
  
  <pre><code>{% extends "base.html" %}
      Hello, ...
      {% include 'sidebar.html' %}
  {% endblock %}
  </code></pre>
  
  <p>The view is:</p>
  
  <pre><code>@app.route('/')
  @app.route('/index')
  def index():
      # some stuff for my index page...
      form_sidebar = sidebar()
      return render_template('index.html', indexdata=indexdata, form_sidebar=form_sidebar)
  </code></pre>
  
  <p>My sidebar form is created with</p>
  
  <pre><code>def sidebar():
      form_sidebar = MySideBarForm()  # defined in forms.py
      # do some sql stuff to initialize the form ...
      return form_sidebar
  </code></pre>
  
  <p>My <code>sidebar.html</code> uses the data received from <code>sidebar()</code>.</p>
  
  <p>If I continue in this manner then every one of my view functions will have to call <code>sidebar()</code>, they will all have to pass along the varialbe <code>form_sidebar</code>, and every template will need to <code>{% include 'sidebar.html' %}</code>. Is there a better way to do this? I think ideally my <code>base.html</code> would <code>{% include 'sidebar.html</code>, but then I don't know how to provide it with the <code>form_sidebar</code> data.</p>