title: Django 1.8: Message in Class-Based View Not Displayed
body: <p>I am writing a simple website using Django 1.8.6 (Python 3.5.0) for rental service. After user created a rent (using a class-based <code>CreateView</code>), user is redirected to rent's index page where a "success" message should be displayed (the index template inherits from <code>base.html</code>).</p>
  
  <p>I read documentation for Django's <a href="https://docs.djangoproject.com/en/1.8/ref/contrib/messages/" rel="nofollow">messages framework</a> and the relevant section for <a href="https://docs.djangoproject.com/en/1.8/ref/contrib/messages/#adding-messages-in-class-based-views" rel="nofollow">adding messages in class-based views</a>.</p>
  
  <p>I added the relevant parts to my code, but after creating a rent, the message is not displayed. the <code>&lt;div id="messages"&gt;</code> (from <code>base.html</code>) is rendered in HTML but no message is displayed (because <code>success_message</code> is not processed in <code>RentCreateView</code>).</p>
  
  <p>My settings:</p>
  
  <p><strong>settings.py (according to docs no additonal setup necessary for Django 1.8):</strong></p>
  
  <pre><code>...
  INSTALLED_APPS = (
      ...
      'django.contrib.sessions',
      'django.contrib.messages',
      'rental_service',
  )
  ...
  MIDDLEWARE_CLASSES = (
      'django.contrib.sessions.middleware.SessionMiddleware',
      'django.contrib.messages.middleware.MessageMiddleware',
      ...
  )
  ...
  TEMPLATES = [
       {
          ...
          'OPTIONS': {
              'context_processors': [
                  'django.template.context_processors.debug',
                  'django.template.context_processors.request',
                  'django.contrib.auth.context_processors.auth',
                  'django.contrib.messages.context_processors.messages',
              ],
          },
       },
  ]
  </code></pre>
  
  <p><strong>base.html (iterates over the messages):</strong></p>
  
  <pre><code>...
  &lt;div id="messages"&gt;
      {% if messages %}
      &lt;ul class="messages"&gt;
          {% for message in messages %}
          &lt;li{% if message.tags %} class="{{ message.tags }}"{% endif %}&gt;{{ message }}&lt;/li&gt;
          {% endfor %}
      &lt;/ul&gt;
      {% endif %}
  &lt;/div&gt;
  ...
  </code></pre>
  
  <p><strong>rent_list.html (extends base.html):</strong></p>
  
  <pre><code>{% extends "base.html" %}
  ...
  </code></pre>
  
  <p><strong>views.py (uses success_message attribute provided by SuccessMessageMixin):</strong></p>
  
  <pre><code>class RentCreateView(CreateView, SuccessMessageMixin):
      model = Rent
      fields = [
          "timestamp_rent",
          "timestamp_return",
          "customer",
          "rental_examples"
      ]
      template_name_suffix = "_create_form"
      success_message = "Rent created successfully." # Ignored: even if "def get_success_message(self, cleaned_data): raise Exception()"
  
      def form_valid(self, form):
          form.instance.user = self.request.user
          return super(RentCreateView, self).form_valid(form)
  
      def get_success_url(self):
          return reverse("rental_service:rent_index")
  </code></pre>