Django

Code

Changeset 5844

Show
Ignore:
Timestamp:
08/11/07 04:37:42 (1 year ago)
Author:
mtredinnick
Message:

Fixed #3526 -- Added content_type as an alias for mimetype to the HttpResponse constructor. It's a slightly more accurate name. Based on a patch from Simon Willison. Fully backwards compatible.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/http/__init__.py

    r5644 r5844  
    213213    status_code = 200 
    214214 
    215     def __init__(self, content='', mimetype=None, status=None): 
     215    def __init__(self, content='', mimetype=None, status=None, 
     216            content_type=None): 
    216217        from django.conf import settings 
    217218        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) 
    220224        if not isinstance(content, basestring) and hasattr(content, '__iter__'): 
    221225            self._container = content 
     
    224228            self._container = [content] 
    225229            self._is_string = True 
    226         self.headers = {'Content-Type': mimetype} 
     230        self.headers = {'Content-Type': content_type} 
    227231        self.cookies = SimpleCookie() 
    228232        if status: 
  • django/trunk/docs/request_response.txt

    r5817 r5844  
    343343------- 
    344344 
    345 ``__init__(content='', mimetype=DEFAULT_CONTENT_TYPE)`` 
     345``__init__(content='', mimetype=None, status=200, content_type=DEFAULT_CONTENT_TYPE)`` 
    346346    Instantiates an ``HttpResponse`` object with the given page content (a 
    347347    string) and MIME type. The ``DEFAULT_CONTENT_TYPE`` is ``'text/html'``. 
     
    350350    return strings, and those strings will be joined together to form the 
    351351    content of the response. 
     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. 
    352362 
    353363``__setitem__(header, value)`` 
     
    397407    These methods make an ``HttpResponse`` instance a file-like object. 
    398408 
     409.. _HTTP Status code: http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10 
     410 
    399411HttpResponse subclasses 
    400412-----------------------