Clever folks, I need your wisdom. I have an app, which uses URL-Dispatch. Couple of days ago I tried to apply new knowledges about Traversal that I had gotten from tutorials. Of course, it doesn't work :)
I would be very thankful, if you might take a look at this code and say where is my problem. (There is the link on GitHub, for convenience)
I'm getting only «404 error», while I'm trying to get response from «/points». And, yes, I'm a newbie not only in «Traversal», but in Pyramid too. As you can see…
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()
Thanks guys from #pyramid IRC (kusut, hello). My mistake is sooo stupid (as it always is) — I put static view at root.
config.add_static_view('/', 'gps_tracker:templates/', cache_max_age=0)
Be careful, don't repeat my mistake…