python quiz with jinja
<p>i'm learning at moment python and for a exercise i have to build a quiz with jinja.
for the quiz i have to build a random function, so that the questions comes random. but i have the problem that my codes don't run the right way. with my code, i get the Error "TypeError: list indices must be integers, not NoneType"
does anybody have a tip, how it might work?</p>

<pre><code>#!/usr/bin/env python
import os
import jinja2
import webapp2
import random


template_dir = os.path.join(os.path.dirname(__file__), "templates")
jinja_env = jinja2.Environment(loader=jinja2.FileSystemLoader(template_dir), autoescape=False)

class BaseHandler(webapp2.RequestHandler):

def write(self, *a, **kw):
    return self.response.out.write(*a, **kw)

def render_str(self, template, **params):
    t = jinja_env.get_template(template)
    return t.render(params)

def render(self, template, **kw):
    return self.write(self.render_str(template, **kw))

def render_template(self, view_filename, params=None):
    if not params:
        params = {}
    template = jinja_env.get_template(view_filename)
    return self.response.out.write(template.render(params))



class MainHandler(BaseHandler):


  def get(self):
        city = cities[secret]
        return self.render_template("index.html", params={"picture" : city.picture, "country" : city.country})

    def post(self):
        capital = self.request.get("capital")
        city = cities[secret]
        if capital == city.name:
            return self.write("That's right :)")
        else:
            return self.write("Sorry, it's wrong")

    class City(object):
        def __init__(self, name, country, picture):
            self.name = name
            self.country = country
            self.picture = picture

cities = [City (name="Vienna""Berlin", country="Austria""Germany", picture="http://www.mpnpokertour.com/wp-content/uploads/2015/08/Slider-Vienna.png""http://polpix.sueddeutsche.com/bild/1.1406949.1355282590/940x528/berlin-staedtetipps-szkorrespondenten.jpg")]
secret = random.seed(len(cities))

app = webapp2.WSGIApplication([
    webapp2.Route('/', MainHandler),
], debug=True)
</code></pre>

<pre><code>secret = random.seed(len(cities))
</code></pre>

<p>This sets <code>secret</code> to <code>None</code>, because the seed function returns nothing.
You probably confused <a href="https://docs.python.org/2/library/random.html#random.seed" rel="nofollow">seed</a> with <a href="https://docs.python.org/2/library/random.html#random.randint" rel="nofollow">randint</a>. Seed is used to initialize the random number generator (usually unneeded as python does it automatically), while randint picks a random number and returns it.</p>

<pre><code>secret = random.randint(0, len(cities) - 1)
</code></pre>

<p>â this will set <code>secret</code> to a random integer between 0 and the number of cities (minus one), inclusive.</p>

python jinja2