django简单使用restframework

下载

pip install djangorestframework

使用

# 添加'rest_framework'到您的INSTALLED_APPS设置:
INSTALLED_APPS = [
    ...
    'rest_framework',
]
# 视图函数 app01/views.py
from rest_framework.views import APIView

class Order(APIView):
    def get(self, request, *args, **kwargs):
        return HttpResponse("GET")

    def post(self, request, *args, **kwargs): return HttpResponse("POST") # 配置路由 settings.py from app01 import views urlpatterns = [ ... url(r'^order/', views.Order.as_view()) ]

django项目启动之后就可以使用GET、POST方式访问http://localhost:port/order/了。

猜你喜欢

转载自www.cnblogs.com/aaronthon/p/12549934.html
今日推荐