"CSRF token missing" with PUT/DELETE meethod rest-framework
<p>I'm using using django rest framework browsable api with ModelViewSet to do CRUD actions and want to use permissions.IsAuthenticatedOrReadOnly, but when I'm logged and try to DELETE or PUT I get
<code>"detail": "CSRF Failed: CSRF token missing or incorrect."</code></p>

<p>My view looks like this</p>

<pre><code>class objViewSet(viewsets.ModelViewSet):
    queryset = obj.objects.all()
    serializer_class = objSerializer
    permission_classes = (permissions.IsAuthenticatedOrReadOnly,)
</code></pre>

<p>Settings.py</p>

<pre><code>REST_FRAMEWORK = {
'DEFAULT_PERMISSION_CLASSES': (
    'rest_framework.permissions.AllowAny',
),
</code></pre>

<p>Serializer is just</p>

<pre><code>class ObjSerializer(serializers.ModelSerializer):
    class Meta:
        model = Obj
</code></pre>

<p>Although when I delete permission_classes (so the default allowAny triggers) I can it works just fine.</p>

<p><strong>What I want</strong></p>

<p>To be able to PUT/DELETE only when I'm authenticated. I don't know how to send CSRF token, when all happens automatically (modalviewset does the whole work)</p>

<p>You might have used SessionAuthentication and session auth checks for the csrf_token always and you can avoid the checks by exempting but Lets not do that. </p>

<p>I think you can keep both Authentication classes. or just TokenAuthentication.  ie,</p>

<pre><code>'DEFAULT_AUTHENTICATION_CLASSES': (
    # 'rest_framework.authentication.BasicAuthentication',
    'rest_framework.authentication.TokenAuthentication',
    'rest_framework.authentication.SessionAuthentication',

    # 'oauth2_provider.ext.rest_framework.OAuth2Authentication',
    # 'rest_framework_social_oauth2.authentication.SocialAuthentication',
),
</code></pre>

<p>And If you are not going for TokenAuth and just the session Auth. you can always pass csrf_token via X-CSRFToken header. Or you just can go for csrf_except things. which will avoid the csrf missing issues. </p>

<p>This should work. Also refer the links below.</p>

<p>ref: <a href="http://stackoverflow.com/a/26639895/3520792">http://stackoverflow.com/a/26639895/3520792</a></p>

<p>ref: <a href="http://stackoverflow.com/a/30875830/3520792">http://stackoverflow.com/a/30875830/3520792</a></p>

python django rest