-1

I'm trying to create a new API file with django-rest-framework and use serializers, but for some reason I keep getting this error even if i do everything exactly as the tutorials(yes, I've tried more than one and they all lead to the same error).

my basic model (Models.py @blog):

class BlogPost(models.Model):
    title=models.CharField(max_length=12)
    description=models.TextField()
    name=models.IntegerField(default=0)

    def __str__(self):
        return self.title

Serializers.py @blog.api:

class BlogPostserializer(serializers.ModelSerializer):

    class Meta:
        model=BlogPost
        fields=('title','description','name')

viewsets.py @blog.api

class BlogPostView(viewsets.ModelViewSet):
    queryset=BlogPost.objects.all()
    serializer_class= BlogPostserializer

Thanks in advance.

  • Does this answer your question? [TypeError: method() takes 1 positional argument but 2 were given](https://stackoverflow.com/questions/23944657/typeerror-method-takes-1-positional-argument-but-2-were-given) – ChrisGPT was on strike Apr 12 '20 at 23:38
  • Without artificial tagging ("(Rest framework, Django)"), this title is forbidden as an exact duplicate of existing questions. That should give you a clue that this is a _bad question_. Please take the [tour] and read [ask]. – ChrisGPT was on strike Apr 12 '20 at 23:41
  • @Chris Yes I checked that (and 2-3 other similar questions) before posting this but the suggested solutions didn't work for me (I believe i have inserted the 'self' argument correctly). – Milad Rezae Apr 12 '20 at 23:53

1 Answers1

0

Answer: Apparently It had something to do with the urls.py file. I switched to using "views" instead of "viewsets", did some modifications to my views.py and added ".as_view()" to my urls.py and it worked(I'm still a bit lost but at least it works now):

urlpatterns=[
    path('',views.BlogpostView**.as_view()**,name='UserList'),
]