Monday, July 23, 2012

Re: Can't access members in a template

Try: {{ u.name }} (with spaces)

On Mon, Jul 23, 2012 at 10:35 AM, twelve_o_clock <twelve_o_clock@lavabit.com> wrote:

I am trying to access data in a template in django. I have a variable u with members name, email, id, and date. However when I put {{u.name}} in a template, it doesn't appear in the HTML file even though just {{u}} appears just fine.

For reference, here is the template:

<html>
<head>
<title>
View user {{ u.id }}
</title>
</head>
<body>
<table>
<tr><td>User ID</td><td>{{u.id}}</td></tr>
<tr><td>User Name</td><td>{{u.name}}</td></tr>
<tr><td>User E-mail</td><td>{{u.email}}</td></tr>
<tr><td>Date/Time joined</td><td>{{u.date}}</td></tr>
</table>
{{u}}
{{i}}
{{u.name}}
</body>
</html>

and here is the function in views.py

def user(request, u):
    u1 = User.objects.filter(id=u)
    return render_to_response('micropost/user.html', {'u':u1, 'i':u})

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/FyEy3rIU1LkJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment