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]
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.
On Fri, 2008-07-04 at 19:20 -0700, Jason wrote: > 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.
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).
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:
> 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.
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.