How to make a POST simple JSON using Django REST Framework? CSRF token missing or incorrect

前端 未结 8 2100
清酒与你
清酒与你 2020-12-04 15:50

Would appreciate someone showing me how to make a simple POST request using JSON with Django REST framework. I do not see any examples of this in the tutorial anywhere?

8条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-04 16:07

    It's from your REST Framework settings. in your settings.py file, your REST_FRAMEWORK should have the following.

    REST_FRAMEWORK = {
        'DEFAULT_AUTHENTICATION_CLASSES': (
            'rest_framework.authentication.TokenAuthentication',
        ),
       'DEFAULT_PERMISSION_CLASSES': (
            'rest_framework.permissions.AllowAny',
        ),
    }
    

    This will set your REST Framework to use token authentication instead of csrf authentication. And by setting the permission to AllowAny, you can authenticate only where you want to.

提交回复
热议问题