How do I return a list as a variable in Python and use in Jinja2?

Viewed 30487

I am a very young programmer and I am trying to do something in Python but I'm stuck. I have a list of users in Couchdb (using python couchdb library & Flask framework) who have a username (which is the _id) and email. I want to use the list of email addresses in a select box in a jinja2 template.

My first problem is how to access the email addresses. If I do:

for user in db:
    doc = db[user]
    emails = doc['email']
    print options

I get:

email@domain.com
otheremail@otherdomain.com
yetanotheremail@yetanotherdomain.com

So I can get my list of emails. But where my brutal inexperience is showing up is that I don't know how to then use them. The list only exists in the for loop. How do I return that list as a useable list of variables? And how do I then make that list appear in my jinja2 template in an option dropdown. I guess I need a function but I am a green programmer.

Would so appreciate help.

3 Answers
Related