title: What is the minimum amount of boilerplate for negotiating content in Django?
body: <p>In a Django application, I have more than a handful of views which return JSON, with an invocation similar to:</p>
  
  <pre><code>return HttpResponse(json.dumps(content), mimetype="application/json")
  </code></pre>
  
  <p>I want to start creating views that return either HTML or JSON depending on the <code>Accept</code> headers from the request. Possibly other types, too, but those are the main ones. I also want to get multiple URLs routed to this view; the file extensions ".html" and ".json" help tell clients which types they should <code>Accept</code> when making their request, and I want to avoid the "?format=json" antipattern.</p>
  
  <p>What's the correct, blessed way to do this in Django with a minimum of boilerplate or repeated code?</p>
  
  <p>(Edit: Rephrase in order to better follow SO's community guidelines.)</p>