1

我正在使用带有活塞的 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()}

由于错误中缺乏详细信息,我无法解决这个问题。/谢谢

4

1 回答 1

0

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

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

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

urlpatterns = patterns('',
    url(r'^search/$', search_resource),
    url(r'^(?P<id>.*)$', annotation_resource),
}
于 2013-05-01T07:28:20.080 回答