rest framework- parser and renderer - long-term maintenance

 

############### ############### parser

# Parser ---- data parser,
# 
# Json distal transmitted data, body inside in the request,
# We need to json data analysis into a dictionary, so every time to resolve, it is possible to create a middleware, as long as json to parse and can be used directly in the view inside,
So what is the # parser? It is to convert the data into the format we need,
# Django does not support the native parsing the json,
# But our rest framework support, without any treatment, you return directly to the dictionary request.data inside,
# from rest_framework.parsers import JSONParser
# This is the rest framework comes json parser,
# You in the view class, adding a word: parser_classes = [JSONParser]
# Add this one, the view class can only parse json data, and can resolve three kinds of default, json, form, multi,

 

Responder ############### ###############

# Responder: response,
# Are httpResponse before use, which is native, which can only use strings,
# from rest_framework.response import Response  # 这是rest framework中的Response,
# His return is a browser-style, there is a page, the data is formatted, it is beautiful, rest framework afraid you visit is not convenient, so have a page, is the Response comes,
# Browser access and access to postman same?
# It is not the same, if it is a browser, considered to be a user, a page,
# Postman visit, only the data, not pages,
# Recommend starting not to use this interface, chaotic, on the use of postman on it,
# Postman installation and use
# Postman a very popular API debugging tools.

  

Guess you like

Origin www.cnblogs.com/andy0816/p/12293733.html