lundi 14 novembre 2016

Where's the syntax error? [on hold]

I'm working on a web app using Google App Engine in the Python version. Its intention is to retrieve a JSON and use it to display HTML content if the q parameter is set, and to show a different template otherwise. In one day of trying variants, I still get the same SyntaxError

class DemoHandler(Handler):
    def get(self):
        q = self.request.get('q')
        answer = {}
        params = { 'q': q }
        if q:
            url = 'http://ift.tt/2g9IDNY' % urllib.urlencode(params)
            try:
                result = urlfetch.fetch(url)
                if result.status_code == 200:
                    answer = json.loads(result.content)
                else:
                    self.response.status_code = result.status_code
            except urlfetch.Error:
                logging.exception('Caught exception fetching url')
            else:
                self.render('template1.html', answer = answer, q = q)
        else: # This line raises a SyntaxError
            self.render('template2.html')

Aucun commentaire:

Enregistrer un commentaire