程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Note: Django rest framework parser

編輯:Python

1, All in all : Give you the data , According to what format , Call it a parser

django In fact, it also comes with a parser , Like that one. JsonResponse() It will return json Class
We use restframework The parser , As long as in the overall situation settings.py For a long time , It does not need to be set separately in the specific views In the middle , That's all right. , as follows :

REST_FRAMEWORK = {

'DEFAULT_VERSIONING_CLASS': 'rest_framework.versioning.URLPathVersioning', # Version class settings 
'DEFAULT_VERSION': 'V1', # Default version 
'DEFAULT_VERSIONS': ['V1', 'V2'], # The default version set 
'DEFAULT_PARSER_CLASSES': ['rest_framework.parsers.JSONParser','rest_framework.parsers.FormParser'] # Set the path of the parser 
}

Note that there are many parsers , For example, upload files , See the source code for details , Then apply it in the specific view ,


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved