django - Wagtail: Intermittent CSRF Verification Error
问题描述
When saving a draft, I have been getting a "CSRF verification failed. Request aborted." error. It happens only intermittently, trying a couple of times to save the draft usually works. I am running Wagtail 2.2.2 and Django 2.0.3, and I have 'django.middleware.csrf.CsrfViewMiddleware'
in my settings.py
file. Here is the error message:
Forbidden (403)
CSRF verification failed. Request aborted.
Reason given for failure:
CSRF token missing or incorrect.
解决方案
This is due to a custom implementation of Shibboleth my organization uses for authentication. It seems that if I previewed a page before saving the draft, the CSRF token was changed by Django, which Shib did not like. In our own code, we extend RemoteUserMiddleware
to use with Shib. So, we changed that to PersistentRemoteUserMiddleware
and it seems to be working now.
推荐阅读
- mysql - 如何在mysql中的某些字符(-)之后对数字进行排序
- python - 我从 psycopg2 收到语法错误。如果我使用 sqlite3 它可以工作
- bash - 为什么我在 bash 中收到有关非整数的错误?
- graph - IFC 通过 python 和 IfcOpenShell 到 Cypher
- c++ - 如何使以下多重继承在 C++ 中工作
- shell - GitHub Actions 工作流程错误:运行命令超时!即使剧本做得很好
- node.js - 在箭头函数节点中设置全局变量
- html - 我的引导导航栏切换器不工作
- java - ListView 列表图标显示
- matplotlib - 如何限制颜色条?