After following the tutorial for Django, I have the baseline of my app up and running, but now I am trying to add some data to one of the templates. I thought I could add this by using extra_context but I am missing something (likely obvious, as I am new to Django). This is what I have in my app's urls.py:
url(r'^$', ListView.as_view(
queryset=Solicitation.objects.order_by('-modified'),
context_object_name='solicitationList',
template_name='ptracker/index.html',
extra_context=Solicitation.objects.aggregate(Sum('solicitationValue'),Sum('anticipatedValue')),
name='index',
)),
The error I am getting is TypeError :
ListView() received an invalid keyword 'extra_context'
What I need to do is somehow get those sums out to the template so that I can display them. How can I do this properly or easily?
extra_context
requires a dict, i.e.:
extra_context={'solicitations': Solicitation.objects...}
EDIT
Sorry, actually, I don't think as_view
actually supports that kwarg. You can try it, but most likely you'll need to subclass the view and override get_context_data
as the docs describe:
def get_context_data(self, **kwargs):
# Call the base implementation first to get a context
context = super(PublisherBookListView, self).get_context_data(**kwargs)
# Add in the publisher
context['publisher'] = self.publisher
return context
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With