【发布时间】:2016-12-14 22:21:04
【问题描述】:
我正在开发一个应用程序,它的前端是一个 AngularJS API,它向在 Django Rest Framework 中开发的后端 API 发出请求。
The frontend is on the domain: https://front.bluemix.net
And my backend is on the domain: https://back.bluemix.net
我在从前端 API 向后端 API 发出请求时遇到问题。错误是这样的:
Error: CSRF Failed: Referer checking failed - https://front.bluemix.net does not match any trusted origins.
我正在使用 CORS,并且我已经在 Django 后端 API 的 settings.py 中包含以下行:
ALLOWED_HOSTS = []
CORS_ALLOW_CREDENTIALS = True
CORS_ORIGIN_ALLOW_ALL = True
CORS_ALLOW_CREDENTIALS = True
CSRF_TRUSTED_ORIGINS = ['https://front.bluemix.net/']
CORS_REPLACE_HTTPS_REFERER = True
CSRF_COOKIE_DOMAIN = 'bluemix.net'
CORS_ORIGIN_WHITELIST = (
'https://front.bluemix.net/',
'front.bluemix.net',
'bluemix.net',
)
有人知道如何解决这个问题吗?
【问题讨论】:
-
您是否按照github.com/ottoyiu/django-cors-headers中的所有步骤操作?
-
是的,我做到了!错误是一样的...
-
可能不支持您的 django 版本。试试这个叉子github.com/zestedesavoir/django-cors-middleware
标签: django django-rest-framework ibm-cloud django-csrf