#26695: views.generic.base.View.options() documentation doesn't match code
--------------------------+------------------------------------------------
     Reporter:  mmoreaux  |      Owner:  nobody
         Type:  Bug       |     Status:  new
    Component:            |    Version:  1.9
  Documentation           |
     Severity:  Normal    |   Keywords:  http dispatch options httpresponse
 Triage Stage:            |  Has patch:  0
  Unreviewed              |
Easy pickings:  0         |      UI/UX:  0
--------------------------+------------------------------------------------
 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,

 {{{#!python
 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:

 {{{#!python
 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

--
Ticket URL: <https://code.djangoproject.com/ticket/26695>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/051.7d794eedc3778b2fb9d86828a20f2849%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to