【问题标题】:Trouble with Pyramid Traversal金字塔遍历的问题
【发布时间】:2014-04-15 19:57:56
【问题描述】:

聪明的人,我需要你的智慧。我有一个使用 URL-Dispatch 的应用程序。几天前,我尝试应用从教程中获得的有关遍历的新知识。当然,它不起作用:)

如果您能看看这段代码并说出我的问题出在哪里,我将不胜感激。 (有link on GitHub,方便)

我只收到 «404 错误»,而我正在尝试从 «/points» 获得响应。而且,是的,我不仅是«Traversal»的新手,也是Pyramid的新手。如您所见……

resources.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()

【问题讨论】:

    标签: python pyramid traversal


    【解决方案1】:

    感谢#pyramid IRC 的各位(kusut,你好)。我的错误太愚蠢了(一如既往)——我把静态视图放在了根目录。

    config.add_static_view('/', 'gps_tracker:templates/', cache_max_age=0)
    

    小心,不要重蹈我的覆辙……

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-12-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-21
      相关资源
      最近更新 更多