Django Rest Framework remove csrf
I know that there are answers regarding Django Rest Framework, but I couldn't find a solution to my problem. I have an application which has authentication and some functionality. I added a new app to it, which uses Django Rest Framework. I want to use the library only in this app. Also I want to make POST request, and I always receive this response:
I have the following code:
I want add the API without affecting the current application. So my questions is how can I disable CSRF only for this app ? |
|||||||||||||
|
Why this error is happening? This is happening because of the default When you don't define any
Since DRF needs to support both session and non-session based authentication to the same views, it enforces CSRF check for only authenticated users. This means that only authenticated requests require CSRF tokens and anonymous requests may be sent without CSRF tokens. If you're using an AJAX style API with SessionAuthentication, you'll need to include a valid CSRF token for any "unsafe" HTTP method calls, such as What to do then? Now to disable csrf check, you can create a custom authentication class
In your view, then you can define the
This should handle the csrf error. |
|||||||||||||||||
|
最新文章
- Spring--通过注解来配置bean【转】
- vim c++补全
- 线性表基本维护[ACM]
- WPF:xmal 静动态资源
- List<;IPoint>; to IPointCollection to IPolygon
- 1053: [HAOI2007]反素数ant - BZOJ
- Redis_基本类型介绍和指令___3
- AWS deepracer
- js的closures(闭包)
- c++数据类型漫谈
- LDAP2-创建OU创建用户
- keil安装
- 20155328 2016-2017-2 《Java程序设计》第7周学习总结
- 用vue实现登录页面
- echarts官网上的动态加载数据bug被我解决。咳咳/。
- 【278】◀▶ Python 数学函数说明
- 分词(Tokenization) - NLP学习(1)
- Kafka+SparkStreaming+Zookeeper(ZK存储Offset,解决checkpoint问题)
- 怎么快速对DB里的所有email进行校验
- 88E1111