mirror of https://github.com/django/django.git
Fixed #19316 -- Set View args/kwargs/request before dispatch
This commit is contained in:
parent
71a3162a70
commit
ea6b95dbec
|
@ -62,6 +62,9 @@ class View(object):
|
|||
self = cls(**initkwargs)
|
||||
if hasattr(self, 'get') and not hasattr(self, 'head'):
|
||||
self.head = self.get
|
||||
self.request = request
|
||||
self.args = args
|
||||
self.kwargs = kwargs
|
||||
return self.dispatch(request, *args, **kwargs)
|
||||
|
||||
# take name and docstring from class
|
||||
|
@ -80,9 +83,6 @@ class View(object):
|
|||
handler = getattr(self, request.method.lower(), self.http_method_not_allowed)
|
||||
else:
|
||||
handler = self.http_method_not_allowed
|
||||
self.request = request
|
||||
self.args = args
|
||||
self.kwargs = kwargs
|
||||
return handler(request, *args, **kwargs)
|
||||
|
||||
def http_method_not_allowed(self, request, *args, **kwargs):
|
||||
|
|
|
@ -216,6 +216,17 @@ class ViewTest(unittest.TestCase):
|
|||
response_allows = set(response['Allow'].split(', '))
|
||||
self.assertEqual(set(expected_methods + ('OPTIONS',)), response_allows)
|
||||
|
||||
def test_args_kwargs_request_on_self(self):
|
||||
"""
|
||||
Test a view only has args, kwargs & request once `as_view`
|
||||
has been called.
|
||||
"""
|
||||
bare_view = InstanceView()
|
||||
view = InstanceView.as_view()(self.rf.get('/'))
|
||||
for attribute in ('args', 'kwargs', 'request'):
|
||||
self.assertNotIn(attribute, dir(bare_view))
|
||||
self.assertIn(attribute, dir(view))
|
||||
|
||||
|
||||
class TemplateViewTest(TestCase):
|
||||
urls = 'regressiontests.generic_views.urls'
|
||||
|
|
Loading…
Reference in New Issue