如何解决Django管理员仅在生产环境上突然注销拒绝执行脚本,因为其MIME类型'text / html'不可执行
每当我在django admin上执行诸如保存,更新或过滤某些内容之类的操作时,就有机会重定向到登录页面,并且需要再次登录。这种行为经常发生,但奇怪的是:它仅在生产环境中发生。我正在使用 AWS fargate 在 ECS集群上运行应用程序。当我检查浏览器存储时,有3个cookie:csrftoken
,sessionid
和djdt
。所有这些都具有很大的到期时间(至少一个星期)。
我的 settings.py 具有以下会话配置:
SESSION_CACHE_ALIAS = 'sessions'
# The module to store session data
SESSION_ENGINE = 'django.contrib.sessions.backends.cache'
# A string like "example.com",or None for standard domain cookie.
SESSION_COOKIE_DOMAIN = env.str('SESSION_COOKIE_DOMAIN',default=None)
# Whether the session cookie should be secure (https:// only).
SESSION_COOKIE_SECURE = not DEBUG
# why it doesn't resolve the sundenly logout problem!?
SESSION_COOKIE_AGE= 24*60*60*7
我尝试了以下问题,但它们对我不起作用:
任何帮助将不胜枚举
编辑 我发现了一些重要的线索:
在我被重定向之前,浏览器的控制台会引发以下错误:
Refused to execute script from '<my_url>/jsl18n' because its MIME type ('text/html') is not executable,and strict MIME type checking is enabled
显示错误消息后,任何单击或与管理员互动都将重定向到登录页面。 我在管理员上使用一些非常简单的JS文件来隐藏/显示基于用户交互的某些字段。我认为这种按摩与这些静态js文件有一些关系。我发现了与此确切错误消息有关的一些问题,而且看起来好像不是特定于Django的。但是这些问题根本没有帮助我。
解决方法
最后我明白了。我已经更改了Public class Student{
@ApiModelProperty(value = "name",name = "name",dataType = "String" example = "Rube")
String name;
@ApiModelProperty(value = "birthDate",name = "birthDate",dataType = "birthDate" example = "12/12/1995")
String birthDate;
........................
}
//should work with following dependencies
<!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger2 -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger-ui -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
:
settings.py
收件人:
SESSION_ENGINE = 'django.contrib.sessions.backends.cache'
CACHES = {
'default': env.cache(
'CACHES_DEFAULT_URL',default='locmemcache://cache-default'),'sessions': env.cache(
'CACHES_SESSIONS_URL',default='locmemcache://cache-sessions'),'memory': env.cache(
'CACHES_MEMORY_URL',default='locmemcache://cache-memory'),}
我不清楚它为什么能工作,但是在集群环境中,本地内存缓存策略可能不是一个好选择。如果有人有更好的猜测,请告诉我。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。