简体   繁体   English

启用了严格的 mime 类型检查,拒绝执行来自 ' 的脚本<url> ' 它的 mime 类型 ('text/plain') 是不可执行的,并且</url>

[英]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.

相关问题 Angular 6:拒绝从“URL”执行脚本,因为它的 MIME 类型()不可执行,并且启用了严格的 MIME 类型检查 - Angular 6 : Refused to execute script from 'URL' because its MIME type( ) is not executable, & strict MIME type checking is enabled 拒绝从 &#39;URL&#39; 执行脚本,因为它的 MIME 类型 (&#39;text/html&#39;) 不可执行,并且启用了严格的 MIME 类型检查 - Refused to execute script from 'URL' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled GeoJSON 文件:拒绝执行脚本,因为其 MIME 类型 (&#39;&#39;) 不可执行,并且启用了严格的 MIME 类型检查 - GeoJSON file: Refused to execute script from because its MIME type ('') is not executable, and strict MIME type checking is enabled 拒绝从“ file_name.php”执行脚本,因为其MIME类型(“ text / html”)不可执行,并且启用了严格的MIME类型检查 - Refused to execute script from 'file_name.php' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled 拒绝执行脚本,因为它的 MIME 类型 ('application/gzip') 不可执行,并且启用了严格的 MIME 类型检查 - Refused to execute script because its MIME type ('application/gzip') is not executable, and strict MIME type checking is enabled 拒绝执行脚本,因为 MIME 类型('text/html')不可执行,并且启用了严格的 MIME 类型检查 - Refused to execute script because MIME type ('text/html') is not executable, and strict MIME type checking is enabled 拒绝应用“ <URL> &#39;,因为它的MIME类型(&#39;text / html&#39;)不是受支持的样式表MIME类型,并且启用了严格的MIME检查 - Refused to apply style from '<URL>' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled 拒绝从&#39;*&#39;执行脚本,因为它的MIME类型(&#39;application / json&#39;)不可执行,并且严格的MIME类型为che - getting Refused to execute script from '*' because its MIME type ('application/json') is not executable, and strict MIME type che 拒绝执行脚本并启用严格的 MIME 类型检查 - Refused to execute script and strict MIME type checking is enabled 拒绝执行脚本,是否启用了严格的 MIME 类型检查? - Refused to execute script, strict MIME type checking is enabled?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM