Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #3526 -- Added content_type as an alias for mimetype to the Htt…

…pResponse constructor. It's a slightly more accurate name. Based on a patch from Simon Willison. Fully backwards compatible.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@5844 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 0afbca9c60206d5005243cb961ff813f2cd6dbf3 1 parent 6fd2c25
Malcolm Tredinnick authored August 11, 2007
12  django/http/__init__.py
@@ -212,18 +212,22 @@ class HttpResponse(object):
212 212
 
213 213
     status_code = 200
214 214
 
215  
-    def __init__(self, content='', mimetype=None, status=None):
  215
+    def __init__(self, content='', mimetype=None, status=None,
  216
+            content_type=None):
216 217
         from django.conf import settings
217 218
         self._charset = settings.DEFAULT_CHARSET
218  
-        if not mimetype:
219  
-            mimetype = "%s; charset=%s" % (settings.DEFAULT_CONTENT_TYPE, settings.DEFAULT_CHARSET)
  219
+        if mimetype:
  220
+            content_type = mimetype     # For backwards compatibility
  221
+        if not content_type:
  222
+            content_type = "%s; charset=%s" % (settings.DEFAULT_CONTENT_TYPE,
  223
+                    settings.DEFAULT_CHARSET)
220 224
         if not isinstance(content, basestring) and hasattr(content, '__iter__'):
221 225
             self._container = content
222 226
             self._is_string = False
223 227
         else:
224 228
             self._container = [content]
225 229
             self._is_string = True
226  
-        self.headers = {'Content-Type': mimetype}
  230
+        self.headers = {'Content-Type': content_type}
227 231
         self.cookies = SimpleCookie()
228 232
         if status:
229 233
             self.status_code = status
14  docs/request_response.txt
@@ -342,7 +342,7 @@ hard-coded strings. If you use this technique, follow these guidelines:
342 342
 Methods
343 343
 -------
344 344
 
345  
-``__init__(content='', mimetype=DEFAULT_CONTENT_TYPE)``
  345
+``__init__(content='', mimetype=None, status=200, content_type=DEFAULT_CONTENT_TYPE)``
346 346
     Instantiates an ``HttpResponse`` object with the given page content (a
347 347
     string) and MIME type. The ``DEFAULT_CONTENT_TYPE`` is ``'text/html'``.
348 348
 
@@ -350,6 +350,16 @@ Methods
350 350
     return strings, and those strings will be joined together to form the
351 351
     content of the response.
352 352
 
  353
+    ``status`` is the `HTTP Status code`_ for the response.
  354
+
  355
+    **(New in Django development version)** ``content_type`` is an alias for
  356
+    ``mimetype``. Historically, the parameter was only called ``mimetype``,
  357
+    but since this is actually the value included in the HTTP ``Content-Type``
  358
+    header, it can also include the character set encoding, which makes it
  359
+    more than just a MIME type specification. If ``mimetype`` is specifiedi
  360
+    (not None), that value is used.  Otherwise, ``content_type`` is used. If
  361
+    neither is given, the ``DEFAULT_CONTENT_TYPE`` setting is used.
  362
+
353 363
 ``__setitem__(header, value)``
354 364
     Sets the given header name to the given value. Both ``header`` and
355 365
     ``value`` should be strings.
@@ -396,6 +406,8 @@ Methods
396 406
 ``write(content)``, ``flush()`` and ``tell()``
397 407
     These methods make an ``HttpResponse`` instance a file-like object.
398 408
 
  409
+.. _HTTP Status code: http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10
  410
+
399 411
 HttpResponse subclasses
400 412
 -----------------------
401 413
 

0 notes on commit 0afbca9

Please sign in to comment.
Something went wrong with that request. Please try again.