I’m trying Google AppEngine and Python today for the first time and managed to get a simple example running. It worked but something wierd is happening: when a URL parameter value changes, it’s not registered unless I restart the app.
In my example below, if I run: http://localhost:8080/?x=hello it will return ‘x is hello’ as it should but if I change the value of X, its new value does not affect the output.
I suspect there is some kind of internal caching going on, but I’m not sure.
from google.appengine.ext import webapp
from google.appengine.ext.webapp import util
import cgi
form = cgi.FieldStorage()
x = form.getvalue('x')
class MainHandler(webapp.RequestHandler):
def get(self):
if x == 'hello':
self.response.out.write('x is hello')
else:
self.response.out.write('x is not hello')
def main():
application = webapp.WSGIApplication([('/', MainHandler)],
debug=True)
util.run_wsgi_app(application)
if __name__ == '__main__':
main()
You’re getting the form value outside the handler, in the module-level code. Obviously, that is defined when the module is first loaded, at the time of the first request. You should be doing that inside the
getmethod.