我尝试为使用django-countries和django rest framework的国家/地区返回一个选择选项列表。我使用JWT_AUTH进行身份验证。
当我尝试选项请求时:
curl -H "Authentication: JWT eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFsYmVydG9fdmVudGEiLCJ1c2VyX2lkIjoyLCJlbWFpbCI6IiIsImV4cCI6MTUwODE2Mzg4Mn0.svxqTThCahSl1Vu27sMjuJyd1PRLk28-Xgn2OKKb5-g" -X OPTIONS -v http://127.0.0.1:8000/api/v1/core/perfilViajeroUserPass/
回复是:
{"name":"Perfil Viajero User Pass Create","description":"","renders":["application/json","text/html"],"parses":["application/json","application/x-www-form-urlencoded","multipart/form-data"]}
但我认为默认情况下它应该是这样的:
{
"name": "To Do List",
"description": "List existing 'To Do' items, or create a new item.",
"renders": [
"application/json",
"text/html"
],
"parses": [
"application/json",
"application/x-www-form-urlencoded",
"multipart/form-data"
],
"actions": {
"POST": {
"note": {
"type": "string",
"required": false,
"read_only": false,
"label": "title",
"max_length": 100
}
}
}
}
有人可以帮助我吗?感谢。
答案 0 :(得分:1)
如果您想更改部分内容:
name
是视图get_view_name
,视图的名称略有改动。description
是视图' get_view_description
,用于修改视图的文档字符串。否则,如果您想要更复杂的内容,您可能希望自定义视图的元数据,如http://www.django-rest-framework.org/api-guide/metadata/#custom-metadata-classes中所述
答案 1 :(得分:0)
我找到了解决方案。
我将我的视图类类型从APIView
更改为generics.CreateAPIView
并知道它有效。非常感谢你。