Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed #19316 -- Set View args/kwargs/request before dispatch

  • Loading branch information...
commit ea6b95dbec77371d517392ffb465017b8eb7001c 1 parent 71a3162
@ghickman ghickman authored claudep committed
View
6 django/views/generic/base.py
@@ -62,6 +62,9 @@ def view(request, *args, **kwargs):
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 @@ def dispatch(self, request, *args, **kwargs):
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):
View
11 tests/regressiontests/generic_views/base.py
@@ -216,6 +216,17 @@ def _assert_allows(self, response, *expected_methods):
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'
Please sign in to comment.
Something went wrong with that request. Please try again.