Answer the question
In order to leave comments, you need to log in
How to get additional arguments in the view?
The documentation talks about passing extra arguments from the url in the view.
Example:
urlpatterns = [
url(r'^blog/(?P<year>[0-9]{4})/$', views.year_archive, {'foo': 'bar'}),]
class BasicCaseView(generic.ListView):
queryset = models.StandardCases.objects.all().filter(type_case='case')
template_name = 'core/basic_modules.html'
context_object_name = 'bases'
path('basic/case/', views.BasicCaseView.as_view(), {'filtr':'case'}, name='basiccase'),
Answer the question
In order to leave comments, you need to log in
In any of the methods of the view class, you can access the named argument with self.kwargs
For example, like this:
class BasicCaseView(generic.ListView):
template_name = 'core/basic_modules.html'
context_object_name = 'bases'
def get_queryset(self):
return models.StandardCases.objects.filter(type_case=self.kwargs['filtr'])
class BasicCaseView(generic.ListView):
def __init__(self):
super(BasicCaseView).__init__()
self.filtr1 = self.kwargs['filtr']
def foo(self):
self.filtr1 # он здесь будет доступен
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question