Django Piston Not Found错误

时间:2013-04-30 11:00:57

标签: python django django-piston

我在活塞上使用Django 1.5。每当我尝试卷曲以下网址时:

http://127.0.0.1:8000/search/?limit=20&uri=

我收到以下错误:

["NotFound"]

网址格式:

search_resource = Resource(handler=SearchHandler)

urlpatterns = patterns('',
    url(r'^', annotation_resource),
    url(r'^search/$', search_resource),

)

和请求的处理程序:

class SearchHandler(AnonymousBaseHandler):
    allowed_methods = ('GET',)
    def read(self, request, id=None):
        non_query_args = ['offset', 'limit', 'all_fields']
        offset = int(request.GET.get('offset', 0))
        limit = int(request.GET.get('limit', 20))
        query=dict([(k,v) for k,v in request.GET.items() if not k in non_query_args])
        notes = Annotations.find(query).limit(limit).skip(offset) #.sort([(, pymongo.DESCENDING if orderDesc else pymongo.ASCENDING)])

        return {'results': [dict([(k,v) if k!='_id' else ('id',v) for k,v in item.items()]) for item in notes],
                'total': notes.count()}

由于错误中缺乏详细程度,我无法解决问题。 /感谢

1 个答案:

答案 0 :(得分:0)

我解决了这个问题。问题出在这里:

def read(self, request, id=None):

删除了id = None并重新排序了url模式,以便它转到正确的处理程序。

urlpatterns = patterns('',
    url(r'^search/$', search_resource),
    url(r'^(?P<id>.*)$', annotation_resource),
}