我正在尝试从Angular 5向DRF创建一个帖子请求。该字段是用户提交的表单。我创建了序列化器,我可以从DRF接口发布一些东西
models.py
class UserForm(models.Model):
id_user_form = models.AutoField(primary_key=True)
user = models.ForeignKey(User, on_delete=models.CASCADE, db_column='idUser', unique=False)
name = models.CharField(max_length=50)
type = models.CharField(max_length=25)
location = models.CharField(max_length=200)
serilizers.py `class UserFormSerializer(serializers.ModelSerializer):
class Meta:
model = UserForm
fields = ('user', 'name', 'type', 'location')
def create(self, validated_data):
user_data = validated_data.pop('user')
user_form = UserForm.objects.create(user_id=user_data, **validated_data)
return user_form
views.py
class FormSubmit(generics.ListCreateAPIView):
queryset = UserForm.objects.all()
serializer_class = UserFormSerializer
当我尝试通过Angular发布时,我收到此错误:
Forbidden (CSRF token missing or incorrect.): /api/form/
我做错了吗?
答案 0 :(得分:0)