[英]strict mime type checking is enabled, refused to execute script from '<url>' its mime type ('text/plain') is not executable, and
I am newbie in Django, and i was working on a Django app.我是 Django 的新手,我正在开发 Django 应用程序。 And i used "media" folder to keep my css and javascript files (i know it's not a good practice) but it was working.
我使用“媒体”文件夹来保存我的 css 和 javascript 文件(我知道这不是一个好习惯),但它正在工作。 Some lines of code
一些代码行
<link href="/media/shop/bootstrap//css/bootstrap.min.css" rel="stylesheet">
<link href="/media/shop/bootstrap//css/bootstrap-responsive.min.css" rel="stylesheet">
<link href="/media/shop/themes/css/bootstrappage.css" rel="stylesheet" />
<script src="/media/shop/themes/js/jquery-1.7.2.min.js"></script>
<script src="/media/shop/bootstrap//js/bootstrap.min.js"></script>
<script src="/media/shop/themes/js/superfish.js"></script>
However what happened i don't know after somedays(today) when i opened this project again and tried to run on local host then i am getting error in console like this然而,当我再次打开这个项目并尝试在本地主机上运行之后,我不知道发生了什么,然后我在控制台中遇到这样的错误
.
.
After clicking on the link present in error it displays my javascript file but not executing it.单击出现错误的链接后,它会显示我的 javascript 文件但不执行它。
And the most weired thing is that when i executed the same file in other system(also on local host) after transferring the same folder then it is working, no any such error in console.最奇怪的是,当我在传输同一个文件夹后在其他系统(也在本地主机上)执行相同的文件时,它正在工作,控制台中没有任何此类错误。 And the same project(website) is also hosted on internet and when i open that site online in my system again then also no any such error.
同样的项目(网站)也托管在互联网上,当我再次在我的系统中在线打开该网站时,也没有任何此类错误。 However when i replace
但是,当我更换
<script src="/media/shop/themes/js/jquery-1.7.2.min.js"></script>
with和
<script type="javascript" src="/media/shop/themes/js/jquery-1.7.2.min.js"></script>
then error not comes in console but it is still not working.然后错误不会出现在控制台中,但它仍然无法正常工作。 I don't think there is any problem with browser setting because i checked in 3 different browsers but it is showing same thing.
我认为浏览器设置没有任何问题,因为我签入了 3 个不同的浏览器,但它显示的是相同的东西。
Any suggestion how to solve this issue and how to disable mime type checking?任何建议如何解决此问题以及如何禁用 mime 类型检查?
Try adding the following code to your settings.py
尝试将以下代码添加到您的
settings.py
import mimetypes
mimetypes.add_type("text/javascript", ".js", True)
It's a solution someone told me.这是有人告诉我的解决方案。 Sadly, it does not come with any explanation.
可悲的是,它没有任何解释。
The script should be type="application/javascript"
脚本应该是
type="application/javascript"
Check your Windows registry key.检查您的 Windows 注册表项。
C:\>reg query HKCR\.js /v "Content Type"
HKEY_CLASSES_ROOT\.js
Content Type REG_SZ text/plain
Update the key as following, it works for me.如下更新密钥,它对我有用。
C:\>reg add HKCR\.js /v "Content Type" /t REG_SZ /d application/javascript
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.