Opened 8 years ago
Closed 8 years ago
#27101 closed Bug (invalid)
args and kwargs not passed in BaseDetailView
Reported by: | Murray Pearson | Owned by: | nobody |
---|---|---|---|
Component: | Generic views | Version: | 1.10 |
Severity: | Normal | Keywords: | BaseDetailView kwargs |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | yes | UI/UX: | no |
Description
In django.views.generic.detail.BaseDetailView's get() method, the arguments and keyword arguments are not passed through for SingleObjectMixin to locate the object. This snippet, from line 110 on, repairs the issue:
class BaseDetailView(SingleObjectMixin, View): """ A base view for displaying a single object """ def get(self, request, *args, **kwargs): ### BUG: args and kwargs are not being stored! self.args = args # Added 8/21/2016 by MJP self.kwargs = kwargs # Added 8/21/2016 by MJP self.object = self.get_object() context = self.get_context_data(object=self.object) return self.render_to_response(context)
The self.args line is probably redundant; I leave it to the developers' judgement whether to include that or not.
Note:
See TracTickets
for help on using tickets.
Hi Autographic,
I'm not sure I understand your report. While
*args
and**kwargs
are passed toBaseDetailView.get()
they are also stored as instance attributes during the dispatching phase.I assume you're hitting this issue because you didn't use the as_view() method of your
BaseDetailView
subclass which takes care of returning the appropriate instance factory.Is it possible that you created the view instance yourself and either passed the
dispatch
orget
method directly to theurl
instance (e.g.url(r'^$', BaseDetailViewSubclass().dispatch)
)?Please refer to the class based view documentation for more details and reopen if you believe this is a Django bug.