python - Django: passing multiple values into the dictionary of the render method -


i try send multiple values render dictionary method, can reach first value in template.

my views.py code:

from django.shortcuts import get_object_or_404, render django.http import httpresponseredirect django.views import generic  books.models import book places.models import symbol  class introview(generic.detailview):     model = book     template_name = 'books/intro.html'  def intro(request, book_id):     book = get_object_or_404(book, pk=book_id)     symbol_list = symbol.objects.all().order_by('name')     return render(request, 'books/intro.html', {'book': book, 'symbol_list': symbol_list}) 

and intro.html template:

{% extends "base.html" %} {% block content %}  <h2>{{ book.name }}</h2> <h3>{{ book.catch_line }}</h3> <em>{{ book.publication_year }}</em>  <hr />  <h4>symbols</h4> {% if symbol_list %}     <ul>     {% symbol in symbol_list %}         <li><img src="{{ symbol.icon.url }}"/>{{ symbol.name }}</li>     {% endfor %}     </ul> {% else %}     <p>no symbols yet...</p> {% endif %}  {% endblock %} 

in template symbol_list empty model have values.

[edit] urls.py file:

from django.conf.urls import patterns, url  books import views  urlpatterns = patterns('',     url(r'^(?p<pk>\d+)/$', views.introview.as_view(), name='intro'), ) 

you're using class-based view introview, don't pass in symbol_list with, identified.

try modifying view follows:

class introview(generic.detailview):     model = book     template_name = 'books/intro.html'      def get_context_data(self, **kwargs):         context = super(introview, self).get_context_data(**kwargs)         context['symbol_list'] = symbol.objects.all().order_by('name')         return context 

Comments