title: Redirect while passing message in django
body: <p>I'm trying to run a redirect after I check to see if the <code>user_settings</code> exist for a user (if they don't exist - the user is taken to the form to input and save them).</p>
  
  <p>I want to redirect the user to the appropriate form and give them the message that they have to 'save their settings', so they know why they are being redirected.</p>
  
  <p>The function looks like this:</p>
  
  <pre><code>def trip_email(request):
      try:
          user_settings = Settings.objects.get(user_id=request.user.id)
      except Exception as e:
          messages.error(request, 'Please save your settings before you print mileage!')
          return redirect('user_settings')
  </code></pre>
  
  <p>This function checks user settings and redirects me appropriately - but the message never appears at the top of the template. </p>
  
  <p>You may first think: <em>"Are messages setup in your Django correctly?"</em></p>
  
  <p>I have other functions where I use messages that are <em>not</em> redirects, the messages display as expected in the template there without issue. Messages are integrated into my template appropriately and work.</p>
  
  <p>Only when I use <code>redirect</code> do I not see the messages I am sending.</p>
  
  <p>If I use <code>render</code> like the following, I see the message (but of course, the URL doesn't change - which I would like to happen).</p>
  
  <pre><code>def trip_email(request):
      try:
          user_settings = Settings.objects.get(user_id=request.user.id)
      except Exception as e:
          messages.error(request, 'Please save your settings before you print mileage!')
          form = UserSettingsForm(request.POST or None)
          return render(request, 'user/settings.html', {'form': form})
  </code></pre>
  
  <p>I have a few other spots where I need to use a <code>redirect</code> because it functionally makes sense to do so - but I also want to pass messages to those redirects.</p>
  
  <p>The <code>user_settings</code> function looks like this:</p>
  
  <pre><code>def user_settings(request):
      try:
          user_settings = Settings.objects.get(user_id=request.user.id)
          form = UserSettingsForm(request.POST or None, instance=user_settings)
      except Settings.DoesNotExist:
          form = UserSettingsForm(request.POST or None)
      if request.method == 'POST':
          settings = form.save(commit=False)
          settings.user = request.user
          settings.save()
          messages.warning(request, 'Your settings have been saved!')
  
      return render(request, 'user/settings.html', {'form': form})
  </code></pre>
  
  <p>I can't find anything in the documentation saying that you <em>can't</em> send messages with redirects... but I can't figure out how to get them to show.</p>
  
  <p><em>Edit:</em> 
  This is how I render the messages in the template:</p>
  
  <pre><code>{% for message in messages %}
    &lt;div class="alert {{ message.tags }} alert-dismissible" role="alert"&gt;
      &lt;button type="button" class="close" data-dismiss="alert" aria-label="Close"&gt;
        &lt;span aria-hidden="true"&gt;&amp;times;&lt;/span&gt;
      &lt;/button&gt;
      {{ message }}
    &lt;/div&gt;
  {% endfor %}
  </code></pre>
  
  <p>I'm not sure if it matters - but it looks like it's almost calling 'GET' twice from somewhere.</p>
  
  <p><a href="https://i.stack.imgur.com/h6qLw.png" rel="noreferrer"><img src="https://i.stack.imgur.com/h6qLw.png" alt="is calling get twice like this normal?"></a></p>
  
  <p>the URL section looks like this for these two URLS:</p>
  
  <pre><code># ex: /trips/email
  url(r'^trips/email/$', views.trip_email, name='trip_email'),
  # ex: /user/settings
  url(r'^user/settings/$', views.user_settings, name='user_settings'),
  </code></pre>