0

i want to pass 2 lists to django template but only first is rendered this is index.html:

enter code here {% if latest_poll_list %} <ul> {% for poll in latest_poll_list %} <li>{{ poll.question }}</li> {% endfor %} </ul> {% else %} <p>No polls are available.</p> {% endif %} {% if menu_items_list %} <table id="menu_items_list"> <tr> {% for item_url, item_name in menu_items_list %} <td><a href="item_url">item_name</a> {% endfor %} </tr> </table> {% endif %} <h3>{{ index_name }}</h3> 

and this is urlconf:

urlpatterns = patterns('zzz.polls.views', url(r'^$', ListView.as_view( queryset=Poll.objects.order_by('pub_date')[:5], context_object_name='latest_poll_list', template_name='index.html')), 

and views:

def index(request): latest_poll_list = Poll.objects.all().order_by('pub_date')[:5] index_name = 'INDEX PAGE' menu_items_list = ['somesite.com', 'Googy') for x in xrange(5)] return render_to_response('index.html', {'latest_poll_list': latest_poll_list, 'menu_items_list' : menu_items_list, 'index_name': index_name}) 

where i make mistake??

1 Answer 1

1

The syntax of the LC is wrong.

>>> ['somesite.com', 'Googy' for x in xrange(5)] File "<stdin>", line 1 ['somesite.com', 'Googy' for x in xrange(5)] ^ SyntaxError: invalid syntax >>> [('somesite.com', 'Googy') for x in xrange(5)] [('somesite.com', 'Googy'), ('somesite.com', 'Googy'), ('somesite.com', 'Googy'), ('somesite.com', 'Googy'), ('somesite.com', 'Googy')] 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.