Google Groups Home
Help | Sign in
dict variable in template
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  6 messages - Collapse all
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
Jason  
View profile
 More options Jul 4, 10:20 pm
From: Jason <jsf80...@gmail.com>
Date: Fri, 4 Jul 2008 19:20:49 -0700 (PDT)
Local: Fri, Jul 4 2008 10:20 pm
Subject: dict variable in template
Hello,

I'm a newbie and using Django in the context of Google App Engine.  In
my Python code I have:
url = users.create_login_url(self.request.uri)
data['attribute1'] = 10
data['attribute2'] = 20
formdata = {
      'data': data,
      'url': url,
      'attribute_list': [attribute1, attribute2]

}

path = os.path.join(os.path.dirname(__file__), 'index.html')
self.response.out.write(template.render(path, formdata))

In index.html I have:
    {% for attribute in attribute_list %}
      <p>{{ attribute }} <input type="text" name="{{ attribute }}"
value="{{ data.attribute }}">
    {% endfor %}

The resulting HTML is:
<p>atttribute1 <input type="text" name="attribute1" value="">
<p>atttribute2 <input type="text" name="attribute2" value="">

What I am wanting is for the 10 and the 20 to appear in the value
attribute of those text boxes.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Russell Keith-Magee  
View profile
 More options Jul 4, 10:25 pm
From: "Russell Keith-Magee" <freakboy3...@gmail.com>
Date: Sat, 5 Jul 2008 10:25:20 +0800
Local: Fri, Jul 4 2008 10:25 pm
Subject: Re: dict variable in template

On Sat, Jul 5, 2008 at 10:20 AM, Jason <jsf80...@gmail.com> wrote:

> Hello,

> I'm a newbie and using Django in the context of Google App Engine.

Hi Jason,

1) Django-developers is a mailing list for discussing the development
of django itself, not for general user queries. Questions like this
one should be asked on django-users.

2) Given that your question is about Google App Engine, you may have
more luck asking in discussion group specific to App Engine. There are
some subtle differences between Google App Engine and Django, so an
answer which is completely correct for Django may be incorrect for App
Engine.

Yours,
Russ Magee %-)


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Malcolm Tredinnick  
View profile
 More options Jul 4, 10:25 pm
From: Malcolm Tredinnick <malc...@pointy-stick.com>
Date: Sat, 05 Jul 2008 12:25:43 +1000
Local: Fri, Jul 4 2008 10:25 pm
Subject: Re: dict variable in template

Django doesn't do indirect lookups like that. The thing after the dot in
{{{ data.attribute }} has to be the name of an attribute, not the name
of a variable that is used to look up the name of an attribute. You
could write a filter to do the indirect lookup for you (I believe there
might even be one in djangosnippets.org), but almost always you'll find
the cleaner solution is not to construct your data that way.

In this case, you can just as easily write:

        {% for name,value in data.items %}
           ...
        {% endfor %}

Alternatively, you could make data be a list of tuples (which would be a
better data structure if you want the results in a well-defined order,
since dictionary orderings will change as you add more things).

Regards,
Malcolm


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Malcolm Tredinnick  
View profile
 More options Jul 4, 10:28 pm
From: Malcolm Tredinnick <malc...@pointy-stick.com>
Date: Sat, 05 Jul 2008 12:28:23 +1000
Local: Fri, Jul 4 2008 10:28 pm
Subject: Re: dict variable in template
And I only just noticed you posted to django-dev instead of
django-users. This isn't the right list for that. Apologies for
answering your question.

Malcolm


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jason  
View profile
 More options Jul 4, 10:39 pm
From: Jason <jsf80...@gmail.com>
Date: Fri, 4 Jul 2008 19:39:40 -0700 (PDT)
Local: Fri, Jul 4 2008 10:39 pm
Subject: Re: dict variable in template
Thanks for the replies, everyone.  I double-checked my message to make
sure it would be clear.  Wonderful!  And yet, I posted to the wrong
group :(  If I have a follow-up I'll post in the users forum or the
Google App Engine forum.

On Jul 5, 2:25 am, "Russell Keith-Magee" <freakboy3...@gmail.com>
wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Dave Smith  
View profile
 More options Jul 4, 11:10 pm
From: "Dave Smith" <davewsm...@gmail.com>
Date: Fri, 4 Jul 2008 20:10:07 -0700
Local: Fri, Jul 4 2008 11:10 pm
Subject: Re: dict variable in template

On Fri, Jul 4, 2008 at 7:39 PM, Jason <jsf80...@gmail.com> wrote:

> Thanks for the replies, everyone.  I double-checked my message to make
> sure it would be clear.  Wonderful!  And yet, I posted to the wrong
> group :(  If I have a follow-up I'll post in the users forum or the
> Google App Engine forum.

There's also an #appengine channel on irc.freenode.net (and, if your
question
is specific to Django, there's also a #django channel). Oft times these will
get you immediate answers.

Dave


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2008 Google