views:

29

answers:

1

Basically, what I'm trying to do is to render os.environ in a template in google app engine. I believe the technology is (or is adapted from) the Django template engine version 0.96 (but correct me if I'm wrong).

I found this question suggesting that you could do:

{{ for key, value in environ}}

But when I try that, I get an error saying:

'for' statements with five words should end in 'reversed': for key, value in environ

I guess that question was concerning another version of Django?

By the way, the value of environ is set to os.environ.items() before rendering the template.

Anyway, I came up a key_value_pair class that I could use instead:

class key_value_pair:
    def __init__(self, key, value):
        self.key = key
        self.value = value

def make_kvp(key, iter):
    return key_value_pair(key, iter[key])

make_kvp is small "factory" method that I later use to set the environ template value like this:

map(lambda x : make_kvp(x, os.environ), os.environ)

When doing that everything works just fine, but since I'm a total newbie to the technologies in play here, I just wanted to make sure that I'm not overseeing some obvious simpler solution.

Thanks in advance for any input.

A: 

Simply iterate over the sequence using a single name, then index the name to get at the individual elements.

Ignacio Vazquez-Abrams
With index you mean like `kvp[0]`? Because I tried that and its not working. But I guess my syntax is incorrect. I'm getting a `Could not parse the remainder: [0]` error.
klausbyskov
No code sample?
S.Lott
You use periods in Django templates to index sequences. `kvp.0`
Ignacio Vazquez-Abrams
@klausbyskov: Use `.` in your template. `kvp.0`. The template language is not Python. You might want to look at more of the Django tutorial.
S.Lott
Thank you very much to both of you. @S.Lott you are completely correct, I *do* have to read a lot more of the Django docs but I have been reading so many (other) docs today and I just wanted to get my feet wet with some coding. And I got stuck. Silly me, but I'm sure you know the feeling.
klausbyskov
"I'm sure you know the feeling". Sadly, no, I don't know that feeling. Sorry.
S.Lott