0

I am trying to make a simple application using Google App Engine.

Below is my code

helloworld.py

print "hello"

class helloworld():
        def myfunc(self):
                st = "inside class"
                return st

test.py

import helloworld

hw_object  = helloworld.helloworld()
print  hw_object.myfunc()

app.yaml

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

- url: /.*
  script: test.py

When I run my application via http://localhost:10000 it prints only hello whereas my expected output is hello and inside class.

My directory structure

E:\helloworld>dir
app.yaml       helloworld.py  test.py

I am pretty sure this has something to do with Script Handlers.So, what is the correct way to define handlers and what is wrong in my way of defining them.

3
  • Do you mean to have two identical route regexps? Commented Feb 21, 2012 at 5:54
  • I mean how can i configure my app.yaml if there are multiple scripts in my folder.I tried the above pattern it didn't worked.What i need is if i run localhost:10000 both my scripts should be executed but this is not happening. Commented Feb 21, 2012 at 5:55
  • @AdamBernier: I tried url: /test/.* but still no luck. Commented Feb 21, 2012 at 6:10

3 Answers 3

3

When your first handler pattern /.* matches http://localhost:10000, the remaining handlers are all ignored.

You can updated your app.yaml

handlers:
- url: /hello
  script: helloworld.py

- url: /test
  script: test.py

And browse http://localhost:10000/test

Sign up to request clarification or add additional context in comments.

Comments

0

Please walk through the Getting Started guide from the appengine documentation. It will help you get through the initial setup problems like this.

http://code.google.com/appengine/docs/python/gettingstarted/helloworld.html

Here is the sample Handler from that documentation.

from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app

class MainPage(webapp.RequestHandler):
    def get(self):
        self.response.headers['Content-Type'] = 'text/plain'
        self.response.out.write('Hello, webapp World!')

application = webapp.WSGIApplication(
                                 [('/', MainPage)],
                                 debug=True)

def main():
    run_wsgi_app(application)

if __name__ == "__main__":
    main()

Note that the class extends webapp.RequestHandler, the method name is get (or post if you are responding to a http post request) Also the extra code at the bottom for setting up the application. You can add extra URL's to the application by adding arguments to the WSGIApplication. For example:

application = webapp.WSGIApplication(
                                 [('/', MainPage)],
                                 [('/help/', HelpPage)],
                                 debug=True)

Also note that in your app.yaml as both scripts refer to the same url pattern, there is no way that any request will ever get to test.py. The normal pattern is to have specific url patterns at the top and a catch-all patter last.

Good Luck.

Comments

0

I had a similar problem too. Expanding on Hamish's answer, and correcting the last part where the square brackets are:

application = webapp.WSGIApplication([
                            ('/', MainPage), 
                            ('/help/', HelpPage)],
                            debug=True)

Reference: https://webapp-improved.appspot.com/guide/routing.html

** Edit I also had an extra closing bracket in my code above. Changed that now.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.