[英]What does format=None do in Django rest full API
Recently when I read Django rest full API document I faced this code:最近,当我阅读 Django rest 完整的 API 文档时,我遇到了这段代码:
def get(self, request, format=None):
"""Return a list of APIView features."""
an_apiview = [
'Uses HTTP methods as function (get, post, patch, put, delete).',
'It is similar to a traditional Django view.',
'Gives you most control over you logic.',
'Its mapped manually to URLs.'
]
return Response({'message': 'Hello!', 'an_apiview': an_apiview})
this code is work fine but I look for format=None
and I cant find out what does it do.这段代码工作正常,但我寻找
format=None
并且我无法找出它的作用。 is any body know what is it and why its important to be?有没有人知道它是什么以及为什么它很重要?
The django rest framework (drf) documentation explains it here . django rest框架(drf)文档在此处进行了说明。
The gist of it is that when you want to support multiple file types in your response, drf provides a shortcut to support this, but requires you to include 'format' as a keyword argument. 要点是,当您想在响应中支持多种文件类型时,drf提供了一种支持此功能的快捷方式,但要求您将“格式”作为关键字参数包括在内。
format() is a built-in function in Python that converts a value into the required format. format() 是 Python 中内置的 function ,它将一个值转换成需要的格式。 Here format is none indicate so specified format is required allow all.
这里的 format 是 none 表示所以需要指定的格式 allow all。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.