Search code examples
pythongoogle-app-enginewsgiwebapp2app.yaml

GAE app.yaml Script Handling for scripts in subdirectories (python)


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

Solution

  • 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