title: Django redirect back to previous page on form post
body: <p>I'm trying to have a form post redirect back to the page it was posted from. So my app has a detail page that displays information about a place, /arena/123, and on the same page there is a form that a user can enter some comments or ratings about the current place they are looking at. These are my view functions.</p>
  
  <pre><code>class DetailView(LoginRequiredMixin, generic.DetailView):
      model = Arena
      template_name = 'arenas/detail.html'
  
      def get_context_data(self, **kwargs):
          context = super(DetailView, self).get_context_data(**kwargs)
          if 'form' not in context:
              print 'no form in context'
              context['form'] = RatingForm
          return context
  
  def rate(request):
      if request.method == 'POST':
          form = RatingForm(request.POST)
          if form.is_valid():
              # post was valid. go back to page and display data
              return DetailView.as_view()(request(), form=RatingForm)
          else:
              # post was unsuccessful. go back to the page and display errors
              print form.errors
              return DetailView.as_view()(request(), form=form)
  </code></pre>
  
  <p>and my template </p>
  
  <pre><code>{% extends "base.html" %}
  {% block content %}
      &lt;h1&gt;{{ arena.address }}&lt;/h1&gt;
      &lt;h1&gt;{{ arena.address_2 }}&lt;/h1&gt;
      &lt;h1&gt;{{ arena.phone }}&lt;/h1&gt;
  
      {% if form.errors %}
          {% for field in form %}
              {% for error in field.errors %}
                  &lt;div class="alert alert-error"&gt;
                      &lt;strong&gt;{{ error|escape }}&lt;/strong&gt;
                  &lt;/div&gt;
              {% endfor %}
          {% endfor %}
          {% for error in form.non_field_errors %}
              &lt;div class="alert alert-error"&gt;
                  &lt;strong&gt;{{ error|escape }}&lt;/strong&gt;
              &lt;/div&gt;
          {% endfor %}
      {% endif %}
      &lt;form action="/arenas/rate/" method="post"&gt;
          {% csrf_token %}
          {{ form }}
      &lt;input type="submit" value="Submit" /&gt;
      &lt;/form&gt;
  
      &lt;div&gt;
          {{comments}}
      &lt;/div&gt;
  {% endblock %}
  </code></pre>
  
  <p>So what I'd like to do is after a user submits the form on the page I'd like to go back to the same detail page I was on and either have the data that user posted there shown in the comments section if it was successful or redirect back to the same page but with the form errors if it was unsuccessful. My problem is right now I don't know how to retain the url and form errors to display the detail page again. I don't think I can use <code>return DetailView.as_view()(context(), form=form)</code> because my DetailView doesn't have a post so I get a 405. Every example I see doesn't cover redirecting back to the same page. They usually just show a <code>HttpResponseRedirect(/thanks)</code> or something similar.</p>
  
  <p>Also note. I don't want to post to /arena/123 because eventually that will be another feature to update information about the place so I didn't want to put the comments post on that url. </p>