- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 tastypie,但遇到了这个错误:
The format indicated 'application/x-www-form-urlencoded' had no available deserialization method. Please check your
formats
andcontent_types
on your Serializer.
我不知道这意味着什么。
这是什么意思以及如何解决这个问题?
在 api.py 中
class UserResource(ModelResource):
class Meta:
queryset = User.objects.all()
fields = ['username', 'id']
include_resource_uri = False
allowed_methods = ['get']
class PostResource(ModelResource):
class Meta:
queryset = Post.objects.all()
include_resource_uri = False
allowed_methods = ['get']
filtering = {
"id": ALL,
}
class CommentResource(ModelResource):
post = fields.ForeignKey(PostResource, 'post')
writer = fields.ForeignKey(UserResource, 'writer', full=True, readonly=True)
parent_comment = fields.ForeignKey('main.api.CommentResource', 'parent_comment', null=True)
class Meta:
queryset = Comment.objects.all()
authorization = Authorization()
include_resource_uri = False
ordering = ['-pub_date']
filtering = {
'post': ALL_WITH_RELATIONS,
'comment': ALL_WITH_RELATIONS,
'parent_comment': ALL_WITH_RELATIONS,
}
在 urls.py 中
from tastypie.api import Api
from main.api import CommentResource, UserResource, PostResource
v1_api = Api(api_name='v1')
v1_api.register(CommentResource())
v1_api.register(UserResource())
v1_api.register(PostResource())
这是回溯...不确定是否有帮助
Traceback (most recent call last):
File "env/local/lib/python2.7/site-packages/tastypie/resources.py", line 211, in wrapper response = callback(request, *args, **kwargs)
File "env/local/lib/python2.7/site-packages/tastypie/resources.py", line 438, in dispatch_list return self.dispatch('list', request, **kwargs)
File "env/local/lib/python2.7/site-packages/tastypie/resources.py", line 470, in dispatch response = method(request, **kwargs)
File "env/local/lib/python2.7/site-packages/tastypie/resources.py", line 1362, in post_list deserialized = self.deserialize(request, request.body, format=request.META.get('CONTENT_TYPE', 'application/json'))
File "env/local/lib/python2.7/site-packages/tastypie/resources.py", line 387, in deserialize deserialized = self._meta.serializer.deserialize(data, format=request.META.get('CONTENT_TYPE', format))
File "env/local/lib/python2.7/site-packages/tastypie/serializers.py", line 267, in deserialize raise UnsupportedFormat("The format indicated '%s' had no available deserialization method.
Please check your ``formats`` and ``content_types`` on your Serializer." % format)
UnsupportedFormat: The format indicated 'application/x-www-form-urlencoded' had no available deserialization method.
Please check your ``formats`` and ``content_types`` on your Serializer.
最佳答案
看起来您正在尝试将 HTML 表单数据提交到 tastypie。 application/x-www-form-urlencoded
是 HTML 表单数据类型的 mimetype/contenttype,另一个是 multipart/form-data
。您可能应该将输入格式设置为 JSON 或 XML。
如果您需要接受来自 HTML 表单的数据,tastypie 可能不是满足您需求的最佳选择。
以下是一些选项:
关于python - django tastypie 和 xml 错误消息 : Please check your `` formats `` and ` `content_types`` on your Serializer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35451086/
我看到 request.env['CONTENT_TYPE'] 和 request.content_type 有两个不同的值。 我从一个单独的应用程序向我的 Rails 应用程序发送一个请求,并将 C
我有两个 api 端点,一个从 http 请求获取文件并使用 python api 将其上传到谷歌云存储桶,另一个再次下载它。在第一个 View 中,我从 http 请求中获取文件内容类型并将其上传到
我有两个 api 端点,一个从 http 请求获取文件并使用 python api 将其上传到谷歌云存储桶,另一个再次下载它。在第一个 View 中,我从 http 请求中获取文件内容类型并将其上传到
如果我正确阅读了文档,那么 Django 中的 FileField 不知道文件的 content_type:https://docs.djangoproject.com/en/2.1/ref/mode
我正在尝试使用通用关系,我的模型如下所示: class Post(models.Model): # Identifiers user = models.ForeignKey(User,
每次我从同一个 Django 项目重建新数据库时,ContentType ID 都不能保证相同。这使得比较两个数据库的数据变得困难。 有没有办法强制为给定的 ContentType/Model 使用
我阅读了以下 django 文档 UploadedFile.content_type The content-type header uploaded with thefile (e.g. text/
我正在开发一个同时使用 Django 注册和 Django 配置文件的项目。我有一个允许用户编辑/创建个人资料的表格,其中包括上传照片。在以下情况下一切正常:创建或编辑了配置文件并且从未上传过图像;编
我正在尝试在两个通用 (content_type) 引用之间创建一个映射表,一个用于“代理”,另一个用于“资源”。 所以我采用通常的方式制作通用外键: content_type = models.Fo
我想知道在使用.net的ZipPackage类时,是否有任何方法可以避免在zip文件中包含[Content_Types] .xml文件。 最佳答案 没有。 Zip软件包不是(常规)Zip文件。它们必须
我正在尝试获取 django models.Model 的 ContentType。不尝试从 ContentType 获取模型,这是我在文档中可以找到的全部内容。例如: model_name = 'F
我们可以通过提供多个content_types来获取所有条目吗: 我有以下代码,只能通过一种 content_type 获取所有条目: cf_space.getEntries({content_typ
我为不同的内容类型创建并注册了不同的 View 。它们工作正常,但仅适用于图像和文件以外的内容类型。我无法使 View 可用于图像内容类型。 图像根本没有布局菜单。尽管如此, View 还是出现在 /
我正在定义一个函数,为模型中上传的每张图片创建缩略图。下面是我的代码: def create_thumbnail(self): if not self.coverphoto:
我正在开发一个名为 app 的 django 应用程序,它是 django 项目的一部分,但我在尝试登录管理员时遇到了一些问题。 import os BASE_DIR = os.path.dirnam
有没有办法在 Flask 中为测试客户端设置默认的 content_type 值? 例如,如果我有以下测试: import unittest class MyTestCase(unittest.Tes
在 Sinatra 中是否可以将 content_type 'application/json' 设为默认值?因为我正在构建一个 REST API。 最佳答案 当然,将 content_type 添加
我有内联,它显示了 contenttype 模型的数据,所以我看到的不是真实对象,而是 content_type 和 object_id 字段。我可以排除这些字段 - 这不是问题,但我也想在下拉列表中
[Rails 3.2.13] 我有一个基于 .text.erb 和 .html.haml 模板发送隐式多部分电子邮件的邮件程序。那里没有问题。 我正在尝试添加一个 after_filter 以有条件地
我想允许我的应用程序允许上传 .vtt 文件。现在它只接受 .txt 文件,但我想为字幕添加 .vtt 功能。 我试过这个 * 没有运气: validates_attachment_content_t
我是一名优秀的程序员,十分优秀!