我试图在我的主 GAE 应用程序中支持或多或少隔离的应用程序,托管在不同的子域中。
我将此子域的处理程序放在“oficina”文件夹内的文件“mediciones.py”中。
所以我有:
- /main.py
- /oficina/mediciones.py
- 在mediciones.py里面:
class Router(webapp2.RequestHandler):
def get(self):
[... code ...]
class Listado(webapp.RequestHandler):
def get(self):
[... code ...]
等所有必要的处理程序。
在“main.py”中:
application = webapp2.WSGIApplication([
DomainRoute('ventas.domain.com',
[webapp2.Route(r'/nueva', handler='oficina.mediciones.MedicionNueva', name="nueva-medicion"),
webapp2.Route(r'/listado', handler="oficina.mediciones.Listado", name="listado-mediciones"),
webapp2.Route(r'/medicion/(\d+)/', handler="oficina.mediciones.MedicionDetalles", name="detalles-mediciones"),
webapp2.Route(r'/rellenar_medicion/(\d+)/', handler="oficina.mediciones.MedicionRellenar", name="rellenar-medicion"),
webapp2.Route(r'/editar_medicion/(\d+)/', handler="oficina.mediciones.MedicionEditar", name="editar-medicion"),
webapp2.Route('/', handler="oficina.mediciones.Router")
]),
('/(.+)',
DirectView),
('/?',
HomeView),
], debug=True)
但是当我尝试访问ventas.domain.com 或ventas.domain.com/listado 时,我得到了以下信息:
Traceback (most recent call last):
File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.5.1/webapp2.py", line 1536, in __call__
rv = self.handle_exception(request, response, e)
File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.5.1/webapp2.py", line 1530, in __call__
rv = self.router.dispatch(request, response)
File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.5.1/webapp2.py", line 1272, in default_dispatcher
self.handlers[handler] = handler = import_string(handler)
File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.5.1/webapp2.py", line 1851, in import_string
return getattr(__import__(module, None, None, [obj]), obj)
ImportStringError: import_string() failed for 'oficina.mediciones.Router'. Possible reasons are:
- missing __init__.py in a package;
- package or module path not included in sys.path;
- duplicated package or module name taking precedence in sys.path;
- missing module, class, function or variable;
Original exception:
AttributeError: 'module' object has no attribute 'Router'
Debugged import:
- 'oficina' found in '/base/data/home/apps/s~pavimentos-arquiservi-web-hrd/11-0-0.361841284178483516/oficina/__init__.pyc'.
- 'oficina.mediciones' found in '/base/data/home/apps/s~pavimentos-arquiservi-web-hrd/11-0-0.361841284178483516/oficina/mediciones/__init__.pyc'.
- 'oficina.mediciones.Router' not found.
(将“Router”替换为“Listado”,或每种情况的适当处理程序)。
处理程序已定义,但为什么没有找到它们?