[英]Django-rest-framework: Browsable API can't get POST data via HTML form, but can from Raw data
Well, the problem is simple. 好吧,问题很简单。 If I post my data via the HTML form, a new record is created in the DB but all data passed is null, as shown in the picture. 如果我通过HTML表单发布数据,那么将在数据库中创建一条新记录,但是传递的所有数据均为空,如图所示。
post response via html form 通过html表单发布回复
However, if a use the "raw_data" interface, everything works just fine: 但是,如果使用“ raw_data”接口,则一切正常:
post response via raw data 通过原始数据发布回复
Code is quite simple: 代码很简单:
views.py: views.py:
class CollectionList(generics.ListCreateAPIView):
queryset = Collection.objects.all()
serializer_class = CollectionSerializer
serializer.py: serializer.py:
class CollectionSerializer(serializers.ModelSerializer):
class Meta:
model = Collection
fields = ('id','title', 'nlikes')
Any suggestion? 有什么建议吗?
You simply need to upgrade django rest framework to 3.3.1. 您只需要将django rest框架升级到3.3.1。 There was a bug in 3.3.0 that sets all form data to empty values when using the session login. 3.3.0中存在一个错误,使用会话登录名时会将所有表单数据设置为空值。
Edit: The issue was https://github.com/tomchristie/django-rest-framework/issues/3574 编辑:问题是https://github.com/tomchristie/django-rest-framework/issues/3574
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.