BaseListView's get_context_data is missing kwargs?

37 views
Skip to first unread message

Ken

unread,
Jul 31, 2015, 10:27:50 PM7/31/15
to Django users
I created a class FilteredListView(BaseListView, FormMixin) so I can have a filter form in my list view.  The form submits filters via GET.  I have it working.  But there is a piece of the code that I feel ought to be handled by django.  In order to get the form into the context, I duplicated BaseListView.get() and changed the line

    context = self.get_context_data()

to 

    context = self.get_context_data(form=form)

BaseListView's get() accepts a kwargs but it is not used anywhere.  It seems to me that it should be passed to get_context_data() since it accepts a kwargs.  If it did, then I would only need to write a small get() method to instantiate (and optionally bind) the form, then call super with the appropriate kwargs argument to complete the get request processing.

Is there some reason why kwargs is not passed to get_context_data()?

Thanks


jordi collell

unread,
Aug 2, 2015, 6:21:00 PM8/2/15
to Django users
Not sure if i'm understanding what are you saying. But kwargs on get.. Are stored on a object property. Self.kwargs (prior the dispatch) method.

jordi collell

unread,
Aug 2, 2015, 6:21:03 PM8/2/15
to Django users

James Schneider

unread,
Aug 2, 2015, 6:41:29 PM8/2/15
to django...@googlegroups.com

Is there a reason you are using BaseListView rather than ListView? The docs mention that BaseListView is not really meant to be used directly. ListView also includes some extra context processing beyond the base class that may be of use.

-James

On Aug 2, 2015 3:21 PM, "jordi collell" <jor...@gmail.com> wrote:
Not sure if i'm understanding what are you saying. But kwargs on get.. Are stored on a object property. Self.kwargs (prior the dispatch) method.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/5375c024-ee41-4b46-816d-e63fadb4a720%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ken

unread,
Aug 3, 2015, 10:37:27 PM8/3/15
to Django users
@Jordi,  Thanks for tip on self.kwargs in View.  That should work.  I'll rewrite my get().

@James - No, no reason in particular.  Wasnt paying attention, I guess.  I was just staring at the get() method in BaseListView and thinking, ah, this is the place I want to inject my filter form into the context.  Thanks for the heads up on the docs.

Thanks for taking the time to respond.

James Schneider

unread,
Aug 3, 2015, 10:55:49 PM8/3/15
to django...@googlegroups.com

No problem. Not sure if you were looking at the source code or somewhere else, but Classy CBV's is always the place I start:

http://ccbv.co.uk/projects/Django/1.8/django.views.generic.list/ListView/

-James

Ken

unread,
Aug 4, 2015, 8:48:55 AM8/4/15
to Django users
Django is really well documented.  So much so, it's an effort to wade through it.  So, sometimes (most times), I resort to looking at the source code.  The downside is you miss these little tips mentioned in the docs, you miss the philosophy behind why it's done a particular way.
Reply all
Reply to author
Forward
0 new messages