title: How to check if django template variable is defined?
body: <p>I have a django template which is used from many views. The template has a block for messages used to notify user of anything that should take their attention. Whether a message is sent or not depends on the views. Some views may send a <code>message</code> variable to the template while others may not. </p>
  
  <pre><code>view_1:
      message = "This is an important message"
      render_to_response("my_template.html", 
                         {'message':message, 'foo':foo, 'bar':bar},
                         context_instance = RequestContext(request))
  
  view_2:
      message = "This is an important message"
      render_to_response("my_template.html", 
                         {'foo':foo, 'bar':bar},
                         context_instance = RequestContext(request))
  </code></pre>
  
  <p>In the template, I check for the <code>message</code> variable and include the block as below:</p>
  
  <pre><code>base_template.html:
      ....
      {% block main_body %}
           {% block messages %}
           {% endblock %}
           {% block content %}
           {% endblock %}
      {% endblock %}
      ....
  
   my_template.html:
       {% extends base_template.html %}
       ....
       {% if message %}
            {% block messages %}
                &lt;div class='imp_msg'&gt;{{ message }} &lt;/div&gt;
            {% endblock %}
       {% endif %}
       ...
  </code></pre>
  
  <p>Problem is that even if view_2 does not pass a message, the final html is rendered with <code>&lt;div class='imp_msg'&gt;&lt;/div&gt;</code> -- basically an empty div. </p>
  
  <p>Since that CSS is designed to give a light_red background to messages, what I see is an empty light_red bar on the top of the page.</p>
  
  <p>I also tried: <code>{% ifnotequal message None %}</code>, <code>{% ifnotequal message '' %}</code>, tried setting the <code>message</code> to <code>None</code> or <code>''</code> explicitly, but does not seem to help.</p>
  
  <p>Would appreciate some help!</p>