Question

I am setting up a new GAE project, and I can't get my scripts in sub-directories to work.

EDIT: If I go to localhost:8080/testing_desc.html I don't any errors, just a blank page (view-source is blank, too). Scripts in my root dir work normally. There is a __init__.py in both the root and sub-dir.

Python script example ("/testing/testing_desc.py"):

import webapp2 as webapp

class DescTstPage(webapp.RequestHandler):
    def get(self):
        html = 'This should work.'
        self.response.out.write(html)

app = webapp.WSGIApplication([('/.*', DescTstPage)], debug=True)

app.yaml:

application: blah
version: blah
runtime: python27
api_version: 1

default_expiration: "5d 12h"

threadsafe: false

libraries:
- name: webapp2
  version: latest


handlers:
- url: /                  <-- This one works
  script: main.app
- url: /index.html        <-- This does NOT work (??)
  script: main.app
- url: /(.*?)_desc.html   <-- Also does NOT work
  script: \1/\1_desc.app
#file not found
- url: /.*
  script: file_not_found.app

I have also tried a simpler version of the yaml:

-url: /testing_desc.html
 script: /testing/testing_desc.app
Was it helpful?

Solution 4

The answer is here: How can i use script in sub folders on gae?

Its not explicitly stated, but in the answer you must change /foo/ to /foo in the WSGIApplication call, which maps to www.bar.com/foo. If you want to map to www.bar.com/foo.html you need to change /foo to /foo.* in the WSGIApplication call AND the url handler in app.yaml to - url: /foo\.html

OTHER TIPS

When you use WSGI Pyhon27 this will work. Use a dot for the seperator :

-url: /testing_desc.html
 script: /testing.testing_desc.app

You are passing a list of routes to your WSGIApplicaiton call. Those routes must match whatever URL is being handled. ('/', DescTstPage) just matches the '/' URL to your handler. /.* matches all routes.

What routes are you setting in testing/testing_desc.app? They must match /testing_desc.html.

To get my scripts working in sub-dir, I changed the app.yaml and /testing/testing_desc.py to this:

app.yaml:

- url: /testing.html
  script: testing/testing_desc.py

/testing/testing_desc.py:

app = webapp.WSGIApplication([('/.*', DescTstPage),], debug=True)

def main():
    run_wsgi_app(app)

if __name__ == '__main__':
    main()

ATM I do not understand how to make the routing work with sub-dir, so I will use this.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top