Two identical pages but only one works

6 views
Skip to first unread message

twelve_o_clock

unread,
Jul 23, 2012, 2:20:01 PM7/23/12
to django...@googlegroups.com

I have a page that I want to list all users and another page which I want to use to list all microposts. The user page works fine but the micropost page does not work even though the two look like they are of an identical format. On the micropost page, I just get an empty table.

Here is part of views.py:

def list(request):
    users = User.objects.all()
    return render_to_response('micropost/list.html', {'users':users})

def micropost_list(request):
    mposts = Micropost.objects.all()
    return render_to_response('micropost/micropost_list.html', {'mposts',mposts})

Here is list.html:

<html>
<head>
<title>
List all Users
</title>
</head>
<body>
<table border="1">
<tr><td><b>ID</b></td><td><b>Name</b></td><td><b>E-mail address</b></td></tr>
{% for u in users %}
 <tr><td> {{ u.id }} </td><td> {{ u.name }} </td><td> {{ u.email }} </td></tr>
{% endfor %}
</table>
</body>
</html>

Here is micropost_list.html:

<html>
<head>
<title>
List all Microposts
</title>
</head>
<body>
<table border="1">
<tr><td><b>ID</b></td><td><b>Content</b></td><td><b>Date Posted</b></td></tr>
{% for m in mposts %}
 <tr><td> {{ m.id }} </td><td> {{ m.content }} </td><td> {{ m.date }} </td></tr>
{% endfor %}
</table>
{{ mposts }}
</body>
</html>

Javier Guerra Giraldez

unread,
Jul 23, 2012, 2:50:40 PM7/23/12
to django...@googlegroups.com
On Mon, Jul 23, 2012 at 1:20 PM, twelve_o_clock
<twelve_...@lavabit.com> wrote:
> return render_to_response('micropost/micropost_list.html',
> {'mposts',mposts})

is that copy/paste? check the dictionary syntax, it should be

{'mposts':mposts}

--
Javier
Reply all
Reply to author
Forward
0 new messages