I am a newbie to Django.. I am wondering why I am getting 'Caught an
exception while rendering: 'Car' object is not iterable?
As per my understanding, in the template, if statement should not be
true and else portion should be executed.
Can anybody help me on this?
View:
--------
def v_list(request,car_number=None):
try:
if car_number!=None:
car_list=Car.objects.get(id=car_number)
else:
car_list=Car.objects.order_by('name')
except:
raise Http404('Requested Info. not found')
cars_render=RequestContext(request,{'car_list':car_list})
return render_to_response('cars.html',cars_render)
Template:
-------------
{% if car_list %}
{% for car in car_list %}
{{car.id}} ,{{car.name}}
{% endfor %}
{%else%}
{{car_list.name}}
{% endif %}