diff --git a/django/core/handlers/wsgi.py b/django/core/handlers/wsgi.py index e9b9f9c1ff..00a9a2ca53 100644 --- a/django/core/handlers/wsgi.py +++ b/django/core/handlers/wsgi.py @@ -68,7 +68,7 @@ class WSGIRequest(http.HttpRequest): def _load_post_and_files(self): # Populates self._post and self._files - if self.environ['REQUEST_METHOD'] == 'POST': + if self.method == 'POST': if self.environ.get('CONTENT_TYPE', '').startswith('multipart'): header_dict = dict([(k, v) for k, v in self.environ.items() if k.startswith('HTTP_')]) header_dict['Content-Type'] = self.environ.get('CONTENT_TYPE', '') diff --git a/django/middleware/cache.py b/django/middleware/cache.py index 5510eba714..80c8626db8 100644 --- a/django/middleware/cache.py +++ b/django/middleware/cache.py @@ -33,7 +33,7 @@ class CacheMiddleware(object): def process_request(self, request): "Checks whether the page is already cached and returns the cached version if available." - if not request.META['REQUEST_METHOD'] in ('GET', 'HEAD') or request.GET: + if not request.method in ('GET', 'HEAD') or request.GET: request._cache_update_cache = False return None # Don't bother checking the cache. @@ -55,7 +55,7 @@ class CacheMiddleware(object): if not hasattr(request, '_cache_update_cache') or not request._cache_update_cache: # We don't need to update the cache, just return. return response - if not request.META['REQUEST_METHOD'] == 'GET': + if request.method != 'GET': # This is a stronger requirement than above. It is needed # because of interactions between this middleware and the # HTTPMiddleware, which throws the body of a HEAD-request diff --git a/django/middleware/common.py b/django/middleware/common.py index acd3233e1d..a42c54751d 100644 --- a/django/middleware/common.py +++ b/django/middleware/common.py @@ -39,7 +39,7 @@ class CommonMiddleware(object): # trailing slash or a file extension. if settings.APPEND_SLASH and (old_url[1][-1] != '/') and ('.' not in old_url[1].split('/')[-1]): new_url[1] = new_url[1] + '/' - if settings.DEBUG and request.META['REQUEST_METHOD'].lower() == 'post': + if settings.DEBUG and request.method == 'POST': raise RuntimeError, "You called this URL via POST, but the URL doesn't end in a slash and you have APPEND_SLASH set. Django can't redirect to the slash URL while maintaining POST data. Change your form to point to %s%s (note the trailing slash), or set APPEND_SLASH=False in your Django settings." % (new_url[0], new_url[1]) if new_url != old_url: # Redirect diff --git a/django/middleware/doc.py b/django/middleware/doc.py index 01c09e9c15..6600e588cd 100644 --- a/django/middleware/doc.py +++ b/django/middleware/doc.py @@ -11,7 +11,7 @@ class XViewMiddleware(object): with an x-header indicating the view function. This is used by the documentation module to lookup the view function for an arbitrary page. """ - if request.META['REQUEST_METHOD'] == 'HEAD' and request.META.get('REMOTE_ADDR') in settings.INTERNAL_IPS: + if request.method == 'HEAD' and request.META.get('REMOTE_ADDR') in settings.INTERNAL_IPS: response = http.HttpResponse() response['X-View'] = "%s.%s" % (view_func.__module__, view_func.__name__) return response diff --git a/django/middleware/http.py b/django/middleware/http.py index 0a8cd67dfa..12d0c0f683 100644 --- a/django/middleware/http.py +++ b/django/middleware/http.py @@ -31,7 +31,7 @@ class ConditionalGetMiddleware(object): response.content = '' response['Content-Length'] = '0' - if request.META['REQUEST_METHOD'] == 'HEAD': + if request.method == 'HEAD': response.content = '' return response diff --git a/django/views/decorators/http.py b/django/views/decorators/http.py index a62c13fb4d..9feb8c0d84 100644 --- a/django/views/decorators/http.py +++ b/django/views/decorators/http.py @@ -17,12 +17,11 @@ def require_http_methods(request_method_list): # I can assume now that only GET or POST requests make it this far # ... - Note that request methods ARE case sensitive. + Note that request methods should be in uppercase. """ def decorator(func): def inner(request, *args, **kwargs): - method = request.META.get("REQUEST_METHOD", None) - if method not in request_method_list: + if request.method not in request_method_list: return HttpResponseNotAllowed(request_method_list) return func(request, *args, **kwargs) return inner diff --git a/django/views/generic/create_update.py b/django/views/generic/create_update.py index c6d7db7af5..b5fdd3e4cc 100644 --- a/django/views/generic/create_update.py +++ b/django/views/generic/create_update.py @@ -106,7 +106,7 @@ def update_object(request, model, object_id=None, slug=None, if request.POST: new_data = request.POST.copy() - if model._meta.has_field_type(FileField): + if model._meta.has_field_type(FileField): new_data.update(request.FILES) errors = manipulator.get_validation_errors(new_data) manipulator.do_html2python(new_data) @@ -178,7 +178,7 @@ def delete_object(request, model, post_delete_redirect, except ObjectDoesNotExist: raise Http404, "No %s found for %s" % (model._meta.app_label, lookup_kwargs) - if request.META['REQUEST_METHOD'] == 'POST': + if request.method == 'POST': object.delete() if not request.user.is_anonymous(): request.user.message_set.create(message="The %s was deleted." % model._meta.verbose_name)