Reputation: 1573
I'm pretty new to django and after a few hours of trying, nothing works.
I have a views.py:
class sspView(generic.ListView):
template_name = 'ssp/sspTableView.html'
context_object_name = 'ssp'
message = "yo, this is the message"
def message(request):
return render(request, 'ssp/sspTableView.html', {'message': message})
def get_queryset(self):
return googleData.objects.order_by('date')
I have a template.html:
{% if ssp %}
<p>total click is: {{ message }}</p>
<table>
{% for googleData in ssp %}
<tr>
<td>{{ googleData.date }}</td>
<td>{{ googleData.account }}</td>
</tr>
{% endfor %}
</table>
{% endif %}
Table renders perfectly, but that message just won't show.
Thank you.
Upvotes: 1
Views: 1834
Reputation: 2949
You can add extra context using get_context_data
method:
def get_context_data(self, **kwargs):
context = super(sspView, self).get_context_data(**kwargs)
context['message'] = 'Hello, context!'
return context
Upvotes: 2
Reputation: 10213
Write only following line or move line outside of if
loop.
<p>total click is: {{ message }}</p>
Why not visible?
because there is if
condition written in template.
{% if ssp %}
Upvotes: 2