聪明的人,我需要你的智慧。我有一个使用URL-Dispatch的应用程序。几天前,我尝试应用我从教程中获得的关于Traversal的新知识。当然,它不起作用:)
如果您可以查看此代码并说出我的问题在哪里,我将非常感激。 (为方便起见,有link on GitHub
我只得到«404错误»,而我正试图从«/ points»得到回应。而且,是的,我不仅是“穿越”的新手,也是金字塔中的新手。正如你所看到的......
resorces.py:
class Resource(object):
def __init__(self, request=None, parent=None, name=None):
self.request = request
self.__parent__ = parent
self.__name__ = str(name)
class Root(Resource):
def __getitem__(self, item):
if item == 'points':
return Points(self.request, self, item)
else:
raise KeyError('Nope')
class Points(Resource):
def __getitem__(self, item):
if item:
return Point(self.request, self, item)
else:
raise KeyError('Nope')
class Point(Resource):
pass
views.py:
def points_get_all(context, request):
return context.__name__
__ INIT __ PY:
from pyramid.config import Configurator
from .resources import (Root, Points)
from .views import points_get_all
def main(global_config, **settings):
config = Configurator(settings=settings, root_factory=Root)
config.add_static_view('static', 'static', cache_max_age=3600)
config.add_view(points_get_all, context=Points, renderer='json')
config.add_static_view('/', 'gps_tracker:templates/', cache_max_age=0)
config.scan()
return config.make_wsgi_app()
答案 0 :(得分:0)
谢谢来自#pyramid IRC的人(kusut,你好)。我的错误是愚蠢的(因为它总是如此) - 我把静态视图放在root。
config.add_static_view('/', 'gps_tracker:templates/', cache_max_age=0)
小心,不要重复我的错误......