Hello, help please
FieldError at /teste/create_teste/
Request Method: | POST |
---|---|
Request URL: | http://127.0.0.1:8000/teste/create_teste/ |
Django Version: | 4.1.2 |
Exception Type: | FieldError |
Exception Value: | Cannot resolve keyword ‘data’ into field. Choices are: id, nome |
here is code
model
from django.db import models
class Teste(models.Model):
nome = models.CharField(max_length = 100)
serializer
from rest_framework import serializers
from .models import Teste
class TesteSerializer(serializers.ModelSerializer):
class Meta:
model = Teste
fields = ‘all’
view
from .models import Teste
from .serializer import TesteSerializer
from rest_framework.decorators import api_view
from rest_framework.response import Response
from rest_framework.parsers import JSONParser
@api_view([‘POST’])
def create_teste(request):
#data = JSONParser().parse(request)
teste = Teste.objects.get(data = request.data)
serializer = TesteSerializer(teste)
if serializer.is_valid():
serializer.save()
return Response(serializer.data)
else:
return Response(serializer.errors)