我正在尝试从https://django-rest-framework.org做一个快速入门教程。
这是我的urls.py
from django.urls import path, include
from rest_framework import routers
from main.views import MovieViewSet, CommentViewSet
router = routers.DefaultRouter()
router.register(r'movies', MovieViewSet)
router.register(r'comments', CommentViewSet)
urlpatterns = [
path('', include(router.urls)),
]
当我去http://127.0.0.1:8000/movies/
时,我会得到
Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8000/movies/
Using the URLconf defined in movie_api.urls, Django tried these URL patterns, in this order:
^$ [name='api-root']
^\.(?P<format>[a-z0-9]+)/?$ [name='api-root']
The current path, movies/, didn't match any of these.
视图集和序列化器的实现如本教程所述。
我累了没看到什么吗?
答案 0 :(得分:0)
将ViewSet
更改为ModelViewSet
后,它可以正常工作。