我正在使用 Django 和 neo4j 开始一个新项目,开发REST服务最有希望的库是 TastyPie ( Django Rest Framework 与ORM绑定,而 neo4j 不是关系数据库)。
我正在关注this tutorial是为了使TastyPîe可以用于非关系数据库,并且我已经覆盖了get方法,但是在尝试访问端点时出现此错误:
Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8000/api/items_manager/items/
Using the URLconf defined in AttractoraGraph.urls, Django tried these URL patterns, in this order:
admin/
api/ general/
api/ items_manager/ items/ ^(?P<resource_name>item)/$ [name='api_dispatch_list']
api/ items_manager/ items/ ^(?P<resource_name>item)/schema/$ [name='api_get_schema']
api/ items_manager/ items/ ^(?P<resource_name>item)/set/(?P<pk_list>.*?)/$ [name='api_get_multiple']
api/ items_manager/ items/ ^(?P<resource_name>item)/(?P<pk>.*?)/$ [name='api_dispatch_detail']
The current path, api/items_manager/items/, didn't match any of these.
这是我的一般 urls.py :
from django.contrib import admin
from django.urls import path
from django.urls import path, include
api_url_patterns = [
path('general/', include('GeneralApp.urls')),
path('items_manager/', include('ItemsManagerApp.urls')),
]
urlpatterns = [
path('admin/', admin.site.urls),
path('api/', include(api_url_patterns)),
这是我的应用程序的 urls.py :
from django.urls import path, include
from ItemsManagerApp import resources
urlpatterns = [
path('items/', include(resources.ItemResource().urls)),
]
这是我的 resources.py :
from tastypie import fields, utils
from tastypie.authorization import Authorization
from tastypie.resources import Resource
from ItemsManagerApp import models
class ItemResource(Resource):
uid = fields.CharField(attribute='uid')
name = fields.CharField(attribute='name')
description = fields.CharField(attribute='description')
created = fields.DateTimeField(default=utils.now, attribute='created')
def get_object_list(self, request):
return list(Item.nodes.all())
def obj_get_list(self, bundle, **kwargs):
return self.get_object_list(bundle.request)
def obj_get(self, bundle, **kwargs):
item = Item.nodes.filter(uid=kwargs['pk'])
return item
我可以看到端点url api/items_manager/items/
在列表中,但是文档中没有引用其他内容。
我将感激任何解决此问题的想法。
答案 0 :(得分:0)
在这种情况下,您可以尝试访问此端点http://127.0.0.1:8000/api/items_manager/items/item/
。
也许this tutorial可以为您提供帮助。