I'm converting a python App Engine Application to use modules as described in this article, https://cloud.google.com/appengine/docs/python/modules/. I would like to use a custom handler as a base class in each of my modules to addd some common functionality. Do I need to repeat my custom handler code in each module, or is there a way to import that class?
For example, I'd like my architecture to look something like this:
MyProject
├── common
│ ├── my_handler.py
├── module1
│ │ ├── module1.yaml
│ │ ├── main.py
├── module2
│ │ ├── module2.yaml
│ │ ├── main.py
/common/my_handler.py is not part of an app engine module and looks like this:
import webapp2
class BaseHandler(webapp2.RequestHandler):
"""
BaseHandler for all requests
"""
pass
And then in the /module1/main.py file, I'd like to do have something like this:
import webapp2
from common.my_handler import BaseHandler
class module1Handler(BaseHandler):
def get(self):
self.response.headers['Content-Type'] = 'text/plain'
self.response.out.write('Hello, this is module 1!')
app = webapp2.WSGIApplication(
[('/', module1Handler),
],
debug=True)
This won't work, the server throws an error as it cannot find common.my_handler.py:
ImportError: No module named common.my_handler
The modules seem to be sandboxed. Is it possible to import /common/my_handler.py from within /module1/main.py?