擅长:python、mysql、java
<p>根据<a href="https://docs.djangoproject.com/en/dev/topics/class-based-views/#decorating-the-class" rel="noreferrer">django docs</a>:</p>
<blockquote>
<p>To decorate every instance of a class-based view, you need to decorate
the class definition itself. To do this you apply the decorator to the
dispatch() method of the class.</p>
</blockquote>
<p>所以你需要做些什么:</p>
<pre><code>class MyView(ApiView):
def POST(self):
# (...)
return HttpResponse(json.dumps(True), mimetype="text/javascript")
@csrf_exempt
def dispatch(self, *args, **kwargs):
return super(MyView, self).dispatch(*args, **kwargs)
</code></pre>