django_tastypie无法识别网址

问题描述 投票:0回答:1

我正在用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/在列表中,但是文档中没有引用其他内容。

我会很感激如何解决这个问题。

python django tastypie
1个回答
0
投票

在这种情况下,您可以尝试访问此端点http://127.0.0.1:8000/api/items_manager/items/item/

也许this tutorial可以帮到你。

© www.soinside.com 2019 - 2024. All rights reserved.