def logIndex(request):
log_data=[]
for log in Log.objects.all()[:50]:
log_element=[log.log_date, log.file, log.lp]
try:
customer = Customer.objects.get(lp=log.lp)
log_element.append(customer.first_name)
log_element.append(customer.last_name)
except Customer.DoesNotExist:
log_element.append(" ")
log_element.append(" ")
log_data.append(log_element)
return render_to_response('Logs.html', {'logs':log_data })
<tbody>
{% for log_date, log_file, log_lp, customer_first_name, customer_last_name in logs %}
<tr>
<th>{{ log_date }}</th>
<th>{{ log_file }}</th>
<th>{{ customer_first_name }}</th>
<th>{{ customer_last_name }}</th>
{% if customer_first_name != " " %}
<th><a href="/customers/{{ log_lp }}"> {{ log_lp }}</a></th>
{% else %}
<th>{{ log_lp }}</th>
{% endif %}
</tr>
{% endfor %}
</tbody>
Also, beware of writing if x when you really mean if x is not None -- e.g. when testing whether a variable or argument that defaults to None was set to some other value. The other value might have a type (such as a container) that could be false in a boolean context!