gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 17:05:14 24 4
gpt4 key购买 nike

我正在尝试为 DRF 设置媒体文件路径/图像,但它不起作用,我无法弄清楚原因。

我收到这个错误:

enter image description here

serve() got an unexpected keyword argument 'documuent_root'

我在 mac 上运行 django 1.11 DRF w/python 3.6。

我已经将设置 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)

最佳答案

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

所以,改为

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

关于Django - serve() 得到了一个意外的关键字参数 'documuent_root',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52069488/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com