Django - serve() 得到了一个意外的关键字参数 'documuent_root'

Django - serve() got an unexpected keyword argument 'documuent_root'

我正在尝试为 DRF 设置媒体文件路径/图像,但它不起作用,我不知道为什么。

我收到这个错误:

serve() got an unexpected keyword argument 'documuent_root'

我正在 mac 运行带有 python 3.6 的 django 1.11 DRF。

我已经将设置 url 移动到顶层,为什么这样 link 所以我更近了一步,虽然我仍然无法弄清楚为什么我的链接在我点击它们时显示 404。

settings.py

MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(os.path.dirname(BASE_DIR), 'src')

STATIC_URL = '/static/'
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static')]

CORS_ORIGIN_WHITELIST = 'localhost:3000', #whitelists the localhost to run

views.py

from accounts.api.permissions import IsOwnerOrReadOnly
from rest_framework import generics, mixins, permissions, viewsets
from books.models import Books
from books.api.serializers import BooksSerializer


class BookViewSet(viewsets.ModelViewSet):
    permission_classes      = [permissions.IsAuthenticatedOrReadOnly, IsOwnerOrReadOnly]    # authentication_classes  = []
    serializer_class        = BooksSerializer  # necessary

    queryset                = Books.objects.all()
    lookup_field            = 'id'
    search_fields           = ('user__username', 'content', 'user__email')
    ordering_fields         = ('user__username', 'timestamp')

urls.py

from django.conf.urls import url, include
from django.contrib import admin
from . import views
from django.conf.urls.static import static
from django.conf import settings
from rest_framework import routers
from books.api.views import (
                BookViewSet)

router = routers.SimpleRouter()
router.register(r'books', BookViewSet) # --> http://127.0.0.1:8000/api/books/api/books/


urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^api/', include(router.urls)),

  ] + static(settings.MEDIA_URL, documuent_root=settings.MEDIA_ROOT)

实际上是一个错字。您使用的是 documuent_root ,但它应该是 document_root.

所以,改为

urlpatterns = [
    .... other patters,
    ]+static(settings.MEDIA_URL, <b>document_root</b>=settings.MEDIA_ROOT)