I am changing a dragon App Engine application to use the module described in this article. I want to use a custom handler as an original class in each of my modules so that I can add some general functionality. Do I need to repeat my custom handler code in each module, or what is the way to import that class is? For example, I want to see my architecture like this:
MyProject ├── Common │ │ my_handler.py ├── module 1 │ │ ├── module 1 yaml │ │ ├ ── main.py ├── module 2 │ │ ├── module2.yaml │ │ ├── main.py
/ common / my_handler.py is not part of the app engine module And looks like this:
import webapp2 class BaseHandler (webapp2.RequestHandler): "" "besassander for all requests" "pass
and Then in the /module1/main.py file, I have to do something like this:
import webapp2 Common.my_handler Import Beasandler Class Module 1 Handler (Beasandler): Def Mill (self): self.response.headers ['Content-type'] = 'Text / plain' Self.response.out.write ('Hello, this Module 1! ') App = Webapp2.WSGIApplication ([(' / ', module1Handler),], debug = true)
This will not work, the server throws an error because its mango My_handler.py:
importError: There is no general named module. My_handler
Module sandboxes appear to be. Is it possible to import / common / my_handler.py at /module/main.py?
There are some things you can try:
sys.path.append (os.path.join (os.pass.dirname (__file__), '..')) Import the common beneficiary as a bassandler
Comments
Post a Comment