django如何使用restful风格

个人比较喜欢restful风格,以为django要安装rest framework才支持restful. 偶然发现只需继承View类即可.

from django.views.generic import View

class TaskView(View):
    # 获取
    def get(self, request, *args, **kwargs):
        print request.GET
    # 新建
    def post(self, request, *args, **kwargs):
        print request.POST
    # 更新
    def put(self, request, *args, **kwargs):
        print request.body
    # 删除
    def delete(self, request, *args, **kwargs):
        print request.body

# 路径配置
#url(r'task/$', TaskView.as_view()),
posted @ 2015-06-07 11:31  妙音  阅读(140)  评论(0编辑  收藏  举报