方式一:
from django.views.decorators.csrf import csrf_exempt
from django.utils.decorators import method_decorator
from django.views import View
class Goods_views(View):
@method_decorator(csrf_exempt)
def dispatch(self, request, *args, **kwargs):
return super(Goods_views,self).dispatch(request, *args, **kwargs)
def post(request):
pass
注:上述代码除了类名(Goods_views)可以替换。其他均不可更改。
方式二:
from django.views.decorators.csrf import csrf_exempt
from django.utils.decorators import method_decorator
from django.views import View
@method_decorator(csrf_exempt,name='dispatch')
class Goods_views(View):
def post(request):
pass