1

My Pyramid アプリは、貼り付け httpserver 内で実行すると正常に動作しますが、Google アプリ エンジンで例外がスローされます。

/hello/{name} URL は、貼り付けサーバーとアプリ エンジンの両方で正常に機能します

/test URL は貼り付けサーバーでは正常に機能しますが、アプリ エンジンでは以下のトレースバックが表示されます。

何か案は?

from pyramid.config import Configurator
from pyramid.response import Response

def hello_world(request):
    return Response('Hello %(name)s!' % request.matchdict)

def test(request):
    return dict()

settings = {'mako.directories':'mako_templates'}
config = Configurator(settings=settings)
config.add_route('hello', '/hello/{name}')
config.add_route('test', '/test', view=test, renderer='test.mako')
config.add_view(hello_world, route_name='hello')

wsgi_app = config.make_wsgi_app()

Google アプリ エンジンからのトレースバック:

ERROR    2013-01-17 02:48:08,893 wsgi.py:235] 
Traceback (most recent call last):
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/runtime/wsgi.py", line 223, in Handle
    result = handler(dict(self._environ), self._StartResponse)
  File "/Users/mnaber/Documents/workspace/UnifiedClassified/site-packages/pyramid/router.py", line 251, in __call__
    response = self.invoke_subrequest(request, use_tweens=True)
  File "/Users/mnaber/Documents/workspace/UnifiedClassified/site-packages/pyramid/router.py", line 227, in invoke_subrequest
    response = handle_request(request)
  File "/Users/mnaber/Documents/workspace/UnifiedClassified/site-packages/pyramid/tweens.py", line 21, in excview_tween
    response = handler(request)
  File "/Users/mnaber/Documents/workspace/UnifiedClassified/site-packages/pyramid/router.py", line 161, in handle_request
    response = view_callable(context, request)
  File "/Users/mnaber/Documents/workspace/UnifiedClassified/site-packages/pyramid/config/views.py", line 367, in rendered_view
    context)
  File "/Users/mnaber/Documents/workspace/UnifiedClassified/site-packages/pyramid/renderers.py", line 531, in render_view
    return self.render_to_response(response, system, request=request)
  File "/Users/mnaber/Documents/workspace/UnifiedClassified/site-packages/pyramid/renderers.py", line 561, in render_to_response
    result = self.render(value, system_values, request=request)
  File "/Users/mnaber/Documents/workspace/UnifiedClassified/site-packages/pyramid/renderers.py", line 534, in render
    renderer = self.renderer
  File "/Users/mnaber/Documents/workspace/UnifiedClassified/site-packages/pyramid/decorator.py", line 39, in __get__
    val = self.wrapped(inst)
  File "/Users/mnaber/Documents/workspace/UnifiedClassified/site-packages/pyramid/renderers.py", line 518, in renderer
    return factory(self)
  File "/Users/mnaber/Documents/workspace/UnifiedClassified/site-packages/pyramid/mako_templating.py", line 129, in __call__
    directories = [ abspath_from_asset_spec(d) for d in directories ]
  File "/Users/mnaber/Documents/workspace/UnifiedClassified/site-packages/pyramid/asset.py", line 43, in abspath_from_asset_spec
    return pkg_resources.resource_filename(pname, filename)
  File "/Users/mnaber/Documents/workspace/UnifiedClassified/site-packages/pkg_resources.py", line 840, in resource_filename
    return get_provider(package_or_requirement).get_resource_filename(
  File "/Users/mnaber/Documents/workspace/UnifiedClassified/site-packages/pkg_resources.py", line 160, in get_provider
    __import__(moduleOrReq)
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/dev_appserver_import_hook.py", line 692, in Decorate
    return func(self, *args, **kwargs)
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/dev_appserver_import_hook.py", line 1766, in load_module
    return self.FindAndLoadModule(submodule, fullname, search_path)
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/dev_appserver_import_hook.py", line 692, in Decorate
    return func(self, *args, **kwargs)
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/dev_appserver_import_hook.py", line 1630, in FindAndLoadModule
    description)
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/dev_appserver_import_hook.py", line 692, in Decorate
    return func(self, *args, **kwargs)
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/dev_appserver_import_hook.py", line 1577, in LoadModuleRestricted
    description)
ImportError: Cannot re-init internal module __main__
INFO     2013-01-17 02:48:08,909 dev_appserver.py:3103] "GET /test HTTP/1.1" 500 -
4

2 に答える 2

1

この件に関する私の背景はかなり浅いので、これは間違っているかもしれません。

これが私の見解です: ピラミッドで mako を使用するには、mako テンプレート ディレクトリを指す「mako.directories」というキーを持つ設定ディクショナリを Configurator に与える必要があります。このキーは、相対パスまたは絶対パスのいずれかです。

pyramid/mako_templating.py ファイルは、次の行で相対パスを絶対パスに変換します。

directories = [ abspath_from_asset_spec(d) for d in directories ]

この変換は gae では機能しません (スタック トレースを参照)。これを回避するために、次のように Pyramid AssetResolver を使用しました。

from pyramid.path import AssetResolver
r = AssetResolver('appname')
full_mako_path = r.resolve('http/mako_templates').abspath()

次に、Pyramid Configurator を作成するときに、次のことを行います。

settings = {'mako.directories':full_mako_path}
config = Configurator(settings=settings)

この場合、私のディレクトリ構造は次のとおりです。

/serve.py (contains wsgi app)
/app.yaml
/appname
/appname/http/mako_templates
...
于 2013-01-18T16:08:17.013 に答える
0

これを試して:

PyramidフォルダーとMakoフォルダーを、アプリ ディレクトリで指定されたディレクトリに配置します。次に、これらのコード行をインポートの下のメイン ファイルに追加します。framework.py

import sys, os
framework_dir = "framework"
framework_dir_path = os.path.join(os.path.dirname(__file__), framework_dir)
sys.path.insert(0, framework_dir_path)
于 2013-01-17T21:52:53.220 に答える