Reputation: 4108
I have an App Engine project structure setup as follows:
My app.yaml looks like this
application: appname
version: 1
runtime: python27
api_version: 1
threadsafe: no
handlers:
- url: /(.*\.html)
mime_type: text/html
static_files: static/\1
upload: static/(.*\.html)
expiration: "1h"
# application scripts
- url: /app/(.+)
script: main.py
# index files
- url: /(.+)/
static_files: static/\1/index.html
upload: static/(.+)/index.html
expiration: "15m"
- url: /(.+)
static_files: static/\1/index.html
upload: static/(.+)/index.html
expiration: "15m"
# site root
- url: /
static_files: static/index.html
upload: static/index.html
expiration: "15m"
libraries:
- name: webapp2
version: "2.5.1"
My main.py is simply the default 'Hello World' sample application:
#!/usr/bin/env python
import webapp2
class MainHandler(webapp2.RequestHandler):
def get(self):
self.response.out.write('Hello world!')
#print("Executing script!")
app = webapp2.WSGIApplication([(r'/app/(.*)', MainHandler)],
debug=True)
Now, the static html can be accessed as expected. The url mapping to the main.py script specified in app.yaml works and I know that the script is getting executed. The trouble I am having is with the URL mapping to be specified to WSGIApplication in main.py. I want to be able to access the application script using the url: localhost:808x/app/something I have already tried using the patterns:
r'/app/(.*)'
r'/(.*)'
r'/'
r'/app/'
None of the above patterns lead to the 'get' response handler being invoked (i.e. I don't get the 'Hello World' response). I have tried gleaning what I am doing wrong from the documentation. I think it all boils down to my only just coming to grips with regular expressions. Would someone possibly be able to point me to what pattern I need to map the application handler to?
Upvotes: 1
Views: 761
Reputation: 3436
How about this pattern?
r'/app/.*'
If there is any regexp grouping, you need arguments for the view function.
Additionally, you need to add main() function in your main.py if you specify your script in the form like main.py
. The main() function looks like:
from google.appengine.ext.webapp.util import run_wsgi_app
...
...
def main():
run_wsgi_app(app)
if __name__ == '__main__':
main()
You can also use this form:
script: main.app
With the latter form, you don't need the main() function.
Upvotes: 1