django rest_framework 视图集没有路由

django rest_framework viewset has no route

我用 django rest_framework 启动了一个新的 django 应用程序。不过有一件事很奇怪——当我尝试快速入门中的示例时,它运行良好:我在 http://localhost:8000/users/ 处获得了一条可以查询的路线。但它不适用于我自己的尽可能小的应用程序。我的路线 http://localhost:8000/listings/ 不可用,我没有收到任何错误。我正在使用 django 1.8.2 和 djangorestframework 3.1.3。

settings.py:

#...
INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'rest_framework',
    'rest_framework_swagger',
    'debug_toolbar',
    'listing',
)
REST_FRAMEWORK = {
    # Use Django's standard `django.contrib.auth` permissions,
    # or allow read-only access for unauthenticated users.
    'DEFAULT_PERMISSION_CLASSES': [
        'rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly'
    ] 
}
#...

urls.py:

from rest_framework import routers, serializers, viewsets
from listing.models import Listing


class ListingSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = Listing
        fields = ('description',)


class ListingViewSet(viewsets.ViewSet):
    queryset = Listing.objects.all()
    serializer_class = ListingSerializer


router = routers.DefaultRouter()
router.register(r'listings', ListingViewSet)

urlpatterns = router.urls

models.py:

from django.db import models


class Listing(models.Model):
    description = models.TextField()

编辑:

错误:

Page not found (404)
Request Method:     GET
Request URL:    http://127.0.0.1:8000/listings/

Using the URLconf defined in djangoway.urls, Django tried these URL patterns, in this order:

    ^__debug__/
    ^$ [name='api-root']
    ^\.(?P<format>[a-z0-9]+)$ [name='api-root']

The current URL, listings/, didn't match any of these.

编辑: 并记下了代码,因为它没有什么奇怪的。

我应该使用 ModelViewSet:

class ListingViewSet(viewsets.ModelViewSet):
                              ^^^^^

感谢 xordoquy 在我打开的 issue 中指出。