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()),


上篇: 开机时让chrome打开指定网页 下篇: python与内建函数重名