Django总是重定向到登录页面[在Chrome和Firefox中,不会发生在Safari中] [英] Django always Redirect to Login Page [in Chrome and Firefox, NOT happens in Safari]
问题描述
为什么每次访问新页面时,我的django应用程序总是弹出登录页面?从chrome的inspect元素中的资源选项卡,我确实看到每次django重定向到登录页面时,会话ID都会更改。这意味着快速会话到期是根本原因?如何修复?
Why does my django app always pop up the login page every time accessing a new page? From the Resource Tab in chrome's inspect element, I do see that session id changes each time django redirecting to the login page. This means, the quick session expiration is the root cause? How shall it be fixed?
这种情况适用于ADMIN用户和普通用户。我正在使用django-allauth,这是长时间没有任何问题的工作。
This happens for both ADMIN user and normal users. I am using the django-allauth which is working without any problem for a long time.
对于管理员用户,点击添加社交应用程序就像这样[只是一个例子,不是真正的链接]
http:// localhost:8080 / admin / login /?next = / admin / socialaccount / socialapp / / a>
For admin user, when clicking 'add social app' it is like this [just an example, not real link] http://localhost:8080/admin/login/?next=/admin/socialaccount/socialapp/
对于普通用户,它是
http:// localhost:8080 / account / login /?next = / some / page /
我的配置django-allauth:
My configuration of django-allauth:
LOGIN_URL = '/accounts/login'
LOGIN_REDIRECT_URL = '/home/'
ACCOUNT_AUTHENTICATION_METHOD = "email" #(=username_email"username" | "email" | "username_email")
ACCOUNT_CONFIRM_EMAIL_ON_GET = False
ACCOUNT_EMAIL_CONFIRMATION_ANONYMOUS_REDIRECT_URL = LOGIN_URL
ACCOUNT_EMAIL_CONFIRMATION_AUTHENTICATED_REDIRECT_URL = LOGIN_REDIRECT_URL
ACCOUNT_EMAIL_CONFIRMATION_EXPIRE_DAYS = 10
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_EMAIL_VERIFICATION = None
ACCOUNT_EMAIL_SUBJECT_PREFIX = "[SITE]: "
ACCOUNT_DEFAULT_HTTP_PROTOCOL = "http"
ACCOUNT_LOGOUT_ON_GET = False
ACCOUNT_LOGOUT_REDIRECT_URL = LOGIN_URL
ACCOUNT_SIGNUP_FORM_CLASS = 'myapp.forms.MyUserCreateForm'
#A string pointing to a custom
ACCOUNT_SIGNUP_PASSWORD_VERIFICATION = True
ACCOUNT_UNIQUE_EMAIL = True
ACCOUNT_USER_MODEL_USERNAME_FIELD = None
ACCOUNT_USERNAME_REQUIRED = False
SOCIALACCOUNT_AUTO_SIGNUP = True
#Enforce uniqueness of e-mail addresses.
ACCOUNT_USER_MODEL_EMAIL_FIELD = "email"
ACCOUNT_USERNAME_BLACKLIST = []
ACCOUNT_PASSWORD_INPUT_RENDER_VALUE = False
ACCOUNT_PASSWORD_MIN_LENGTH = 6
ACCOUNT_LOGIN_ON_EMAIL_CONFIRMATION = True
推荐答案
我做了两件事,现在似乎消失了。
I did two things, and the issue seems to disappear for now.
- 更新我的chrome / firefox
-
将其添加到settings.py
- Update my chrome/firefox
Add this into the settings.py
SESSION_COOKIE_AGE = 1209600#2周内过期
SESSION_COOKIE_AGE = 1209600 #expire in 2 weeks
然而,第二个是自动由Django从文档配置。可能我的一些使用Cookie的javascripts会影响到期时间
However, the 2nd one is automatically configured by Django from the docs. Probably some of my javascripts playing with cookies affect the expiration time
这篇关于Django总是重定向到登录页面[在Chrome和Firefox中,不会发生在Safari中]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!