1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| from django.views.decorators.csrf import csrf_exempt, csrf_protect
def index(request): if request.method == 'POST': username = request.POST.get('username') money = request.POST.get('money') target_user = request.POST.get('target_user') print('%s 给 %s 转了 %s 元钱'%(username,target_user,money)) return render(request,'index.html')
from django.utils.decorators import method_decorator
from django import views
class MyLogin(views.View): @method_decorator(csrf_exempt) def dispatch(self, request, *args, **kwargs): return super().dispatch(request,*args,**kwargs)
def get(self,request): return HttpResponse('from get')
def post(self,request): return HttpResponse('from post') """ csrf_exempt该装饰器在CBV中只能给dispatch装才能生效 """
|