Sucheta Ghoshal
Sucheta Ghoshal

Reputation: 21

app.yaml file for a python program

How do I write an app.yaml file for a particular Python app I'm trying to put on Google App Engine?

Here is the simple python code I'm trying to work on:

import webapp2
form="""
<form action="http://www.google.com/search">
<input name="q">
<input type="submit">
</form>
"""
class MainPage(webapp2.RequestHandler):
    def get(self):
        self.response.out.write(form)

app=webapp2.WSGIApplication([('/',MainPage)],
                              debug=True)

Now whenever I'm trying to run it on Google App Engine, it simply doesn't work. Shows nothing on localhost and shows server error while deploying it.

Here is the app.yaml code:

application: saaps-2012
version: 1
runtime: python
api_version: 1

handlers:
- url: /.*
script: program.py

Upvotes: 1

Views: 208

Answers (1)

Littm
Littm

Reputation: 4947

Try to add the following lines in the end of your file program.py:

def main():
    app.run()

if __name__ == "__main__":
    main()

Your file should then look like something like this:

import webapp2
form="""
<form action="http://www.google.com/search">
<input name="q">
<input type="submit">
</form>
"""
class MainPage(webapp2.RequestHandler):
    def get(self):
        self.response.out.write(form)

app=webapp2.WSGIApplication([('/',MainPage)],
                              debug=True)

def main():
    app.run()

if __name__ == "__main__":
    main()

Have a try and let me know about your results.

Upvotes: 2

Related Questions