title: django redirect to previous url after CreateView
body: <p>I'd like to return to the url of a DetailView(BuildingUnitDetail) that called the CreateView, UpdateView, and DeleteView after a Submit. ex: <a href="http://127.0.0.1:8000/unit/13/" rel="nofollow">http://127.0.0.1:8000/unit/13/</a></p>
  
  <p>I've found several other questions/answers regarding redirects to previous view but I couldn't get any of the solutions to work for me. Mostly because I don't understand them. It seems that it should be a straight forward solution and I'm overthinking them.</p>
  
  <p>Is there a painless solution out there?</p>
  
  <p>Any help would be greatly appeciated, been at this for over 2 days</p>
  
  <p>#urls.py</p>
  
  <pre><code>from django.conf.urls import url
  from . import views
  from cdpapp.views import BuildingList, BuildingDetail, BuildingUnitDetail, CreateWorkOrder, EditWorkOrder, DeleteWorkOrder
  
  
  urlpatterns = [
      url(r'^$', BuildingList.as_view(), name='index'),
      url(r'^building/(?P&lt;pk&gt;\d+)/$', BuildingDetail.as_view(), name='building_detail'),
      url(r'^unit/(?P&lt;pk&gt;\d+)/$', BuildingUnitDetail.as_view(), name='building_unit_detail'),
      url(r'^workorder/add/$', CreateWorkOrder.as_view(), name='workorder_add'),
      url(r'^workorder/(?P&lt;pk&gt;\d+)/$', EditWorkOrder.as_view(), name='workorder_update'),
      url(r'^workorder/(?P&lt;pk&gt;\d+)/delete/$', DeleteWorkOrder.as_view(), name='workorder_delete'),
  ]
  </code></pre>
  
  <p>#views.py</p>
  
  <pre><code>class BuildingUnitDetail(DetailView):
      model = Unit
      template_name = 'cdpapp/building_units_detail.html'
      context_object_name = 'units'
  
  
  class CreateWorkOrder(CreateView):
      template_name = 'cdpapp/workorder_form.html'
      model = WorkOrder
      success_url = reverse_lazy('back to calling url')
  
  
  class EditWorkOrder(UpdateView):
      template_name = 'cdpapp/workorder_form.html'
      model = WorkOrder
      success_url = reverse_lazy('back to calling url')
  
  
  class DeleteWorkOrder(DeleteView):
      template_name = 'cdpapp/workorder_form.html'
      model = WorkOrder
      success_url = reverse_lazy('back to calling url')
  </code></pre>
  
  <p>#forms.py</p>
  
  <pre><code>class WorkOrderForm(forms.Form):
      building = forms.ModelChoiceField(queryset=Building.objects.all())
      unit = forms.ModelChoiceField(queryset=Unit.objects.all())
      ...
  </code></pre>
  
  <p>#form template</p>
  
  <pre><code>{% block content %}
  &lt;form method="POST"&gt; {% csrf_token %}
      {{ form.as_p }}
      &lt;input class="btn btn-danger" type="submit" value="Submit"&gt;
  &lt;/form&gt;
  {% endblock content %}
  </code></pre>