下载

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/了。

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-06
  • 2022-12-23
  • 2022-12-23
  • 2021-04-12
猜你喜欢
  • 2021-06-12
  • 2021-10-12
  • 2021-11-04
  • 2021-06-08
  • 2021-12-05
  • 2022-02-13
  • 2022-12-23
相关资源
相似解决方案