You should actually return the context from your get_context_data
! So change it like this
def get_context_data(self, **kwargs): context = super(board_lv, self).get_context_data(**kwargs) context['c_board'] = self.Board; return context
Question
Here's the relevant view:
class board_lv(generic.ListView):
template_name = 'boardList.html'
context_object_name = 'notice_List'
def get_queryset(self):
self.Board = get_object_or_404(Board, name=self.args[0])
if self.args[0] == 'all':
return Notice.objects.order_by('-posted_on')
else:
return Notice.objects.filter(board=self.Board)
def get_context_data(self, **kwargs):
context = super(board_lv, self).get_context_data(**kwargs)
context['c_board'] = self.Board;
And here is the html template:
<h1>/b/ {{c_board}}</h1>
<ul>
{% for n in notice_list %}
<li>
{% if not n.isText %}
<h2><a href="{{ n.content }}">{{ n.title }}</a></h2>(/b/{{n.board}})<br>
{% else %}
<h2><a href= "{% url 'detail' n.id %}">{{ n.title }}</a></h2>(/b/{{n.board}})
<p>{{ n.content|slice:":100" }}</p>
{% endif %}
<a href="{% url 'detail' n.id %}">Comments</a>{{n.thumbs_up}}
</li>
{% endfor %}
</ul>
When I navigate to a board url which calls this view, all that shows is the first "/b/" in the top left corner. I'm guessing there's an issue with the contexts but I can't put my finger on it.
Any help would be greatly appreciated.
La solution
You should actually return the context from your get_context_data
! So change it like this
def get_context_data(self, **kwargs): context = super(board_lv, self).get_context_data(**kwargs) context['c_board'] = self.Board; return context