Hello, 

I have written my application in Django 2.0. Now I want to use 
rest_framework, I was not aware that documentation for 2.0 is not here.
My articles/api/views.py

from rest_framework import generics
from yogavidya.apps.articles.models import Article
from .serializers import ArticleSerializer
from rest_framework import routers, serializers, viewsets

class ArticleUpdateView(generics.ListCreateAPIView):
  lookup_field = 'pk'
  serializer_class = ArticleSerializer
  queryset = Article.objects.all()
 
  def get_queryset(self):
    return Article.objects.all()

  def get_object(self):
    pk = self.kwargs.get("pk")
    return Article.objects.get(pk=pk)

 


and articles/api/urls.py

from django.urls import path, include
from django.conf.urls.i18n import i18n_patterns
from .views import ArticleUpdateView
from django.urls import re_path
app_name = 'api'
urlpatterns = [
    path(r'', ArticleUpdateView, name="api-articles"),
]
 
 

Now I try to add it in my project/urls.py

from rest_framework import routers, serializers, viewsets
router = routers.DefaultRouter(trailing_slash=False)
router.register(r'articles/', ArticleUpdateView.as_view(), 
base_name='api-articles')
...
urlpatterns += [
    path('api/articles/', include(router.urls)),
]

now when I change "router.register(r'articles/', ArticleUpdateView, 
base_name='api-articles')"

I get 
  File "/home/ytsejam/public_html/api_yogavidya/yogavidya/urls.py", line 
59, in <module>
    path('api/articles/', include(router.urls)),
  File 
"/home/ytsejam/.virtualenvs/yogavidya_dev/lib/python3.6/site-packages/rest_framework/routers.py",
 
line 91, in urls
    self._urls = self.get_urls()
  File 
"/home/ytsejam/.virtualenvs/yogavidya_dev/lib/python3.6/site-packages/rest_framework/routers.py",
 
line 359, in get_urls
    urls = super(DefaultRouter, self).get_urls()
  File 
"/home/ytsejam/.virtualenvs/yogavidya_dev/lib/python3.6/site-packages/rest_framework/routers.py",
 
line 286, in get_urls
    view = viewset.as_view(mapping, **initkwargs)
TypeError: as_view() takes 1 positional argument but 2 were given



I know my code can be confused because of my trials. But how can I view 
queryset in Django 2.0.

Thanks

-- 
You received this message because you are subscribed to the Google Groups 
"Django REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to