2
Unless you’re looking to have all of the addresses after all of the users, put the second loop inside the first.
You’re passing users
, a collection of User
objects to the template rendering. User
doesn’t have a street_address
field – Address
does. You’ll need to pass Address
objects to the form.
It also appears that street_address
is just a CharField
, not any sort of list.
If user
had a street_address
field, you could simply do:
{% for user in users %}
<li>{{ user }}</li>
<li>{{ user.street_address }}</li>
{% endfor %}
Since it doesn’t, look instead into this:
def all(request):
addresses = Address.objects.all()
return render_to_response('all.html', locals(), context_instance=RequestContext(request))
and
{% for address in addresses %}
<li>{{ address.user }}</li>
<li>{{ address.street_address }}</li>
{% endfor %}
Source:stackexchange.com