im trying to set up media file path / images for DRF but its not working and i cant figure out why.
i get this error:
serve() got an unexpected keyword argument 'documuent_root'
I am on mac runing django 1.11 DRF w/ python 3.6.
I have moved the settings urls to top level by why way of this link so i am one step closer although i still cant figure out why my links show 404 when i click on them.
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)
Its a typo actually. You were using documuent_root
, but it should be document_root
.
So, change to
urlpatterns = [
.... other patters,
]+static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)