title: Redirect from Generic View DetailView in Django
body: <p>I'm using Django's class based DetailView generic view to look up an object for display.  Under certain circumstances, rather than displaying the object, I wish to back out and issue a HTTP rediect instead.  I can't see how I go about doing this.  It's for when a user hits an object in my app, but without using the canonical URL.  So, for example, on StackOverflow URLs take the form:</p>
  
  <pre><code>http://stackoverflow.com/&lt;content_type&gt;/&lt;pk&gt;/&lt;seo_friendly_slug&gt;
  </code></pre>
  
  <p>eg:</p>
  
  <pre><code>http://stackoverflow.com/questions/5661806/django-debug-toolbar-with-django-cms-and-django-1-3
  </code></pre>
  
  <p>You can actually type anything as the seo_friendly_slug part and it will redirect you to the correct canonical URL for the object looked up via the PK.</p>
  
  <p>I wish to do the same in my DetailView.  Retrieve the object, check that it's the canonical URL, and if not redirect to the item's get_absolute_url URL.</p>
  
  <p>I can't return an HttpResponseRedirect in get_object, as it's expecting the looked up object.  I can't seem to return it from get_context_data, as it's just expecting context data.</p>
  
  <p>Maybe I just need to write a manual view, but I wondered if anyone knew if it was possible?</p>
  
  <p>Thanks!</p>
  
  <p>Ludo.</p>