Reputation: 87
Working with the Django REST Framework i encountered quite a big problem. Here is what my problem looks like: CreateAPIView not showing Form
What I currently have at serializers.py:
class TaskCreateSerializer(serializers.ModelSerializer): # Create
class Meta:
model = Task
fields = ('title')
At views.py:
class TaskCreateAPIView(CreateAPIView): # Create
queryset = Task.objects.all()
serializer_class = TaskCreateSerializer
And at urls.py:
path('tasks/create/', TaskCreateAPIView.as_view(), name='create_tasks')
So basically i can't create any task objects
What I tried:
class TaskCreateSerializer(serializers.ModelSerializer): # Create
title = serializers.CharField() # New line (does not work)
class Meta:
model = Task
fields = ('title')
Thanks in advance!
Upvotes: 0
Views: 463
Reputation: 4034
You are missing a comma in fields tuple. Either use list, or ('title', ). Otherwise, in Python it is just a string in parentheses. Maybe that's the issue. Also you have to choose POST method in the drop down at top-right. Just noticed, are you sure about "v1" part of URL? Maybe it shouldn't be there, it looks like this URL is not being resolved at all.
Upvotes: 1