Django

Code

Changeset 3164

Show
Ignore:
Timestamp:
06/19/06 22:48:31 (2 years ago)
Author:
adrian
Message:

Added 'method' attribute to HttpRequest objects

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/core/handlers/modpython.py

    r2809 r3164  
    9999            return self._raw_post_data 
    100100 
     101    def _get_method(self): 
     102        return self.META['REQUEST_METHOD'].upper() 
     103 
    101104    GET = property(_get_get, _set_get) 
    102105    POST = property(_get_post, _set_post) 
     
    106109    REQUEST = property(_get_request) 
    107110    raw_post_data = property(_get_raw_post_data) 
     111    method = property(_get_method) 
    108112 
    109113class ModPythonHandler(BaseHandler): 
  • django/trunk/django/core/handlers/wsgi.py

    r2809 r3164  
    5656        self.path = environ['PATH_INFO'] 
    5757        self.META = environ 
     58        self.method = environ['REQUEST_METHOD'].upper() 
    5859 
    5960    def __repr__(self): 
  • django/trunk/django/http/__init__.py

    r3144 r3164  
    1313    pass 
    1414 
    15 class HttpRequest(object): # needs to be new-style class because subclasses define "property"s 
     15class HttpRequest(object): 
    1616    "A basic HTTP request" 
    1717    def __init__(self): 
    1818        self.GET, self.POST, self.COOKIES, self.META, self.FILES = {}, {}, {}, {}, {} 
    1919        self.path = '' 
     20        self.method = None 
    2021 
    2122    def __repr__(self): 
     
    283284 
    284285def get_host(request): 
    285     """Gets the HTTP host from the environment or request headers.""
     286    "Gets the HTTP host from the environment or request headers.
    286287    host = request.META.get('HTTP_X_FORWARDED_HOST', '') 
    287288    if not host: 
  • django/trunk/docs/request_response.txt

    r3144 r3164  
    3030    Example: ``"/music/bands/the_beatles/"`` 
    3131 
     32``method`` 
     33    A string representing the HTTP method used in the request. This is 
     34    guaranteed to be uppercase. Example:: 
     35 
     36        if request.method == 'GET': 
     37            do_something() 
     38        elif request.method == 'POST': 
     39            do_something_else() 
     40 
    3241``GET`` 
    3342    A dictionary-like object containing all given HTTP GET parameters. See the 
     
    3746    A dictionary-like object containing all given HTTP POST parameters. See the 
    3847    ``QueryDict`` documentation below. 
     48 
     49    It's possible that a request can come in via POST with an empty ``POST`` 
     50    dictionary -- if, say, a form is requested via the POST HTTP method but 
     51    does not include form data. Therefore, you shouldn't use ``if request.POST`` 
     52    to check for use of the POST method; instead, check `method`_. 
    3953 
    4054    Note: ``POST`` does *not* include file-upload information. See ``FILES``.