I've started new django project and enabled admin app. I can login to admin site but when I'm trying to add/change site or user I'm getting

我已经启动了新的django项目并启用了管理员应用程序。我可以登录管理站点,但是当我尝试添加/更改网站或用户时,我正在获取

CSRF verification failed. Request aborted.
Reason given for failure:
CSRF token missing or incorrect.

That's what I have in settings.py:

这就是我在settings.py中所拥有的:

TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
)

MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
# Uncomment the next line for simple clickjacking protection:
# 'django.middleware.clickjacking.XFrameOptionsMiddleware',
)
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',
)

When I'm looking at admin page source I see

当我在查看管理页面源代码时,我看到了

<input type='hidden' name='csrfmiddlewaretoken' value='T9Mfk1LRXi5jPE2dh5jcvdKwzYM6Iy5I' />

there

I have Django version 1.4.1

我有Django版本1.4.1

2 个解决方案

#1


6

Have you overridden the CSRF_COOKIE_DOMAIN setting? If the CSRF token is present in the form, and you haven't modified the source of the admin app, then the most likely scenario is that the cookie is not being set correctly.

您是否覆盖了CSRF_COOKIE_DOMAIN设置?如果表单中存在CSRF令牌,并且您尚未修改管理应用程序的源,则最可能的情况是未正确设置cookie。

Check the response headers of the login page to make sure that the cookie is being set correctly, and check the request headers of your login attempt to ensure that it is also being sent (and matches the value in the form).

检查登录页面的响应标头以确保正确设置cookie,并检查登录尝试的请求标头以确保它也被发送(并匹配表单中的值)。

更多相关文章

  1. Django -表单无效但没有错误
  2. 轮询Web服务的最佳方式(例如,对于Twitter应用程序)
  3. 如何在/account / url模式之外使用Django-AllAuth注册表单?
  4. 乘客的Django应用程序显示空主页
  5. 用于在Google App Engine上构建应用程序的最佳开源IDE?
  6. 获取Android应用程序的Linux UID
  7. 在Linux中的脚本中安装应用程序
  8. 如何发送一个字节(或字节)来测试在我的应用程序中监听的套接字?
  9. 〖Linux〗使用Qt5.2.0开发Android的NDK应用程序

随机推荐

  1. Android(安卓)初始化NavigationView的hea
  2. android中数据存储
  3. 【Android】学习记录 -- 初识ffmpeg
  4. AndroidStudio Unknown attribute androi
  5. android之focusable的使用
  6. Android横屏预竖屏
  7. 移动端H5的Video标签无法播放在线视频的
  8. 使用Android Studio调试smail源码
  9. Android:Error retrieving parent for it
  10. Android下拉列表