I'm creating a simple blog application and I am trying to convert django rest api. But, I got this error
TypeError at /user/api/ hasattr(): attribute name must be string
Exception Type: TypeError at /user/api/
Exception Value: hasattr(): attribute name must be string
this is my models.py file
from django.conf import settings
from django.db import models
from django.urls import reverse
class BlogPost(models.Model):
author = models.ForeignKey(settings.AUTH_USER_MODEL,on_delete=models.CASCADE)
blog_title=models.CharField(max_length=200)
blog_description=models.TextField()
blog_pub=models.DateTimeField(auto_now_add=True)
blog_update=models.DateTimeField(auto_now=True)
def __str__(self):
return self.blog_title
def get_absolute_url(self):
return reverse('blog:blog_post', kwargs={'pk': self.pk})
this is my serializers.py file
from rest_framework import serializers
from blog.models import BlogPost
class BlogPostSerializer(serializers.ModelSerializer):
class Meta:
fields=(
'author',
'blog_title',
'blog_description',
),
model=BlogPost
This is views.py file
from blog.models import BlogPost
from .serializers import BlogPostSerializer
from rest_framework import generics
from . import serializers
from . import serializers
class BlogPostListAPI(generics.ListCreateAPIView):
queryset=BlogPost.objects.all()
serializer_class=BlogPostSerializer
class BlogPostListAPIDetail(generics.RetrieveUpdateDestroyAPIView):
queryset = BlogPost.objects.all()
serializer_class = serializers.BlogPostSerializer
this is urls.py file
from django.urls import path,include
from .views import SignUpForm, UserProfiles
from .api.views import *
urlpatterns = [
path('signup/', SignUpForm.as_view(), name='signup'),
path('profile/', UserProfiles.as_view(), name='profile'),
path('api/', BlogPostListAPI.as_view(), name='asad'),
path('api/<int:pk>', BlogPostListAPIDetail.as_view()),
]

hasttris usedswitch to copy and paste viewand paste in that error in the updated error. should likely list then where it crashed.BlogPostSerializer