标签:pip install work def res include none cbv support
1、回顾CBV基本使用
from django.contrib import admin from django.urls import path,re_path,include urlpatterns = [ path(‘admin/‘, admin.site.urls), re_path(r‘users/‘,include((‘users.urls‘, ‘users‘), namespace=‘users‘)) ]
from django.contrib import admin from django.urls import path,re_path,include urlpatterns = [ path(‘admin/‘, admin.site.urls), re_path(r‘users/‘,include((‘users.urls‘, ‘users‘), namespace=‘users‘)) ]
import json from django.shortcuts import render,HttpResponse from django.views import View class HomeView(View): def dispatch(self, request, *args, **kwargs): return super(HomeView, self).dispatch(request, *args, **kwargs) def get(self, request): return HttpResponse(‘get‘) def post(self, request): return HttpResponse(‘post‘)
2、安装DjangoRestFramework
pip install djangorestframework==3.9.2 pip install markdown==3.0.1 # Markdown support for the browsable API. pip install django-filter==2.1.0 # Filtering support
3、DjangoRestFramework 基本使用
urlpatterns = [ url(r‘^users‘, Users.as_view()), ]
from django.views import View from django.http import JsonResponse class Users(View): def get(self, request, *args, **kwargs): result = { ‘status‘: True, ‘data‘: ‘response data‘ } return JsonResponse(result, status=200) def post(self, request, *args, **kwargs): result = { ‘status‘: True, ‘data‘: ‘response data‘ } return JsonResponse(result, status=200)
1111
标签:pip install work def res include none cbv support
原文地址:https://www.cnblogs.com/xiaonq/p/10987889.html