dJANGO RESTFRAMEWORK
2015-07-23 20:14
731 查看
1、filter_queryset
class ProductAdd(generics.ListCreateAPIView): queryset = Product.objects.all() serializer_class = ProductSerializer filter_fields = ("status", "sale_supplier")#传入参数过滤 template_name = "product_add.html" permission_classes = (permissions.IsAuthenticated,) def get(self, request, *args, **kwargs): queryset = self.filter_queryset(self.queryset)#根据参数进行过滤 page = self.paginate_queryset(queryset) ……
Authentication 授权 Auth needs to be pluggable. 认证需要是可插拔的!! — Jacob Kaplan-Moss, "REST worst practices"
2、Request Response objects
REST框架介绍了request对象继承常规HttpRequest,提供更灵活的请求解析。请求对象的核心功能是request.data属性,这是类似于request.post,但对于Web API的工作更有用。request.post #只处理表单数据. "post" only request.data #处理任意数据。"post" "put" "patch"
REST框架还引入了一个response的对象
return Response(data) # Renders to content type as requested by the client.
If you’re doing REST-based web service stuff … you should ignore request.POST.
— Malcom Tredinnick, Django developers group
相关文章推荐
- django 1.8 官方文档翻译: 2-1-3 元选项 (初稿)
- CF560C Gerald's Hexagon 六边形能切成多少正三角形
- golang
- hdoj 1824 Let's go home 【2-sat 简单题目】
- MangoDB基本操作
- Andriod开机LOGO和开机动画修改
- django安装异常
- DJANGO获取用户访问IP
- Algorithms—21.Merge Two Sorted Lists
- Django项目文件分布及解释
- Django笔记 —— 高级视图和URL配置
- LINGO基本问题
- LINGO基本问题
- LINGO解线性规划
- Django框架下在URLconf中指定视图缓存的方法
- Codeforces Round #313 (Div. 2) C. Gerald's Hexagon(补大三角形)
- 详解Django框架中的视图级缓存
- HDU 1754 I Hate It(线段树)
- HDU 1698 Just a Hook (线段树)
- Django中的CACHE_BACKEND参数和站点级Cache设置