Django3.x报错"Refused to execute script from '<URL>' because its MIME type ('text/plain') "问题处理
Win11系统在本地启动项目后页面元素不能正常显示,js未能正常加载,报错如下:
Refused to execute script from '<URL>' because its MIME type ('text/plain') is not executable, and strict MIME type checking is enabled.
127.0.0.1/:1 Refused to execute script from 'http://127.0.0.1:8000/static/admin/simpleui-x/js/vue.min.js?_=2022.7.29' because its MIME type ('text/plain') is not executable, and strict MIME type checking is enabled.
127.0.0.1/:1 Refused to execute script from 'http://127.0.0.1:8000/static/admin/simpleui-x/elementui/index.js?_=2022.7.29' because its MIME type ('text/plain') is not executable, and strict MIME type checking is enabled.
127.0.0.1/:1 Refused to execute script from 'http://127.0.0.1:8000/static/admin/simpleui-x/js/login.js?_=3.3' because its MIME type ('text/plain') is not executable, and strict MIME type checking is enabled.
127.0.0.1/:1 Refused to execute script from 'http://127.0.0.1:8000/static/admin/simpleui-x/particles/particles.js' because its MIME type ('text/plain') is not executable, and strict MIME type checking is enabled.
127.0.0.1/:1 Refused to execute script from 'http://127.0.0.1:8000/static/admin/simpleui-x/particles/app.js' because its MIME type ('text/plain') is not executable, and strict MIME type checking is enabled.
操作系统把扩展名为js的文件类型注册为 'text/plain', 正确的应为'application/javascript'
问题处理:使用mimetypes模块重新注册解决:
#在settings.py中增加如下代码
import mimetypes
mimetypes.add_type('application/javascript', '.js')
如果有其他文件类型也可以使用mimetypes.add_type添加进去,强刷浏览器或清空缓存重新访问系统恢复正常。
Tag标签:「模块 django mimetypes」更新时间:「2024-02-23 09:27:42」阅读次数:「2132」