Answer the question
In order to leave comments, you need to log in
Why is the ViewSet not being routed and registered?
I have a model class:
models.py
from __future__ import unicode_literals
from django.db import models
# Модель
class Message(models.Model):
msg_date = models.DateTimeField(auto_now_add=True)
text = models.TextField()
readed = models.BooleanField()
from rest_framework import serializers
from .models import Message
class MessageSerializer(serializers.ModelSerializer):
class Meta:
model = Message
fields = ('id', 'title', 'body', 'created_at')
from rest_framework import viewsets
from .models import Message
from .serializers import MessageSerializer
class MessageViewSet(viewsets.ModelViewSet):
aueryset = Message.objects.all().order_by('-created_at')
serializer_class = MessageSerializer
from django.conf.urls import url, include
from django.contrib import admin
urlpatterns = [
url(r'^api/v1/', include('webapp.urls')),
url(r'^admin/', admin.site.urls),
]
from rest_framework import routers
from .views import MessageViewSet
# Создаем router и регистрируем наш ViewSet
router = routers.DefaultRouter()
router.register(r'message', MessageViewSet)
# URLs настраиваются автоматически роутером
urlpatterns = router.urls
router.register(r'message', MessageViewSet)
File "/home/username/.local/lib/python3.5/site-packages/rest_framework/routers.py", line 82, in register
base_name = self.get_default_base_name(viewset)
File "/home/username/.local/lib/python3.5/site-packages/rest_framework/routers.py", line 161, in get_default_base_name
assert queryset is not None, '`base_name` argument not specified, and could ' \
AssertionError: `base_name` argument not specified, and could not automatically determine the name from the viewset, as it does not have a `.queryset` attribute.
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question