#26695 closed Bug (fixed)
views.generic.base.View.options() documentation doesn't match code
Reported by: | Marcel Moreaux | Owned by: | nobody |
---|---|---|---|
Component: | Documentation | Version: | 1.9 |
Severity: | Normal | Keywords: | http dispatch options httpresponse |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
The documentation for views.generic.base.View.options() says:
options(request, *args, kwargs)
Handles responding to requests for the OPTIONS HTTP verb. Returns a list of the allowed HTTP method names for the view.
However,
class Some(View): def options(self, request, **kwargs): return ['GET', 'OPTIONS']
Results in
Traceback (most recent call last): File "/.../django/core/handlers/base.py", line 235, in get_response response = middleware_method(request, response) File "/.../django/middleware/clickjacking.py", line 31, in process_response if response.get('X-Frame-Options') is not None: AttributeError: 'list' object has no attribute 'get'
The relevant Django code is:
def dispatch(self, request, *args, **kwargs): if request.method.lower() in self.http_method_names: handler = getattr(self, request.method.lower(), self.http_method_not_allowed) else: handler = self.http_method_not_allowed return handler(request, *args, **kwargs) def options(self, request, *args, **kwargs): response = http.HttpResponse() response['Allow'] = ', '.join(self._allowed_methods()) response['Content-Length'] = '0' return response
So, from the looks of it, Django expects options()
to return a HttpResponse
object, in line with e.g. get()
and post()
, in direct contradiction of the documentation.
[1] https://docs.djangoproject.com/en/1.9/ref/class-based-views/base/#django.views.generic.base.View.options
Change History (5)
comment:1 by , 9 years ago
comment:2 by , 9 years ago
I will suggest a bit more verbose doc "Returns a response with the list of the allowed HTTP method names in Allow
header for the view"
If we change the sentence to "Returns a response with the list of the allowed HTTP method names for the view." does the clarify it for you?