Closed willson556 closed 4 years ago
Hi @willson556,
the get_file() method can respond to URL parameters
What about using view's self.args
and self.kwargs
in get_file()
method?
View's attributes such as request
, args
, and kwargs
are set by Django's as_view()
magic: see https://github.com/django/django/blob/1.9.6/django/views/generic/base.py#L66-L67
As an example, if URLConf looks like:
year_view = sampleviews.YearDownloadView.as_view()
urlpatterns = [
url(r'^files/(?P<year>[0-9]{4})/$', year_view),
]
... then you should be able to use "year" from self.kwargs
:
class YearDownloadView(VirtualDownloadView):
def get_file(self):
year = self.kwargs['year']
# ... Do something with year...
Does it apply to your use case? Else can you tell me more about the situation where *args
and **kwargs
are mandatory?
I had missed that Django saves the args and kwargs as instance variables. That does resolve my specific use case.
With that knowledge, my only argument for including this PR would be consistency with other CBV's in Django which almost all pass the args and kwargs around (for better or worse) to almost all commonly overriden methods.
Resolves #120.