Django 中的 Javascript 模块管理(已关闭)

标签 javascript jquery django django-staticfiles django-static

我正在开发一个项目,该项目有多个包含不同功能的 .js 文件。 我想在 M2.js 中使用 M1.js 中的函数,我正在做的是从 M1.js 中导出函数并在 M2.js 中导入。

导出工作正常,但问题出在我导入函数时。

M1.js
--export {function}

M2.js
--import {function} from './M1.js'

<script type="module" href="{% static 'myapp/M1.js'%}
<script type="module" href="{% static 'myapp/M2.js'%}

上面是在导入时生成以下错误的代码

Loading module from “app.com/static/Invoicing/exif_js” was blocked because of a disallowed MIME type (“text/html”).

我的目录结构是

-Project
 |--project
 |--Invoicing (App)
   |--static
     |--Invoicing
       |--M1.js
       |--M2.js
   |--templates
   |--etc
 |--static
 |--etc



最佳答案

尝试将 index.html 中的基本 href 更改为当前目录

改变这个

<base href="/">

对此

<base href="./">

关于Django 中的 Javascript 模块管理(已关闭),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66381165/

相关文章:

javascript - 从服务器加载已经存在的 HTML 文件而不是浏览器缓存

javascript - 最小化和关闭按钮在 Electron 应用程序中不起作用

javascript - 我怎样才能让 fullpage.js 允许我的页面也垂直滚动?

django - 如何使用 "reverse"或等效项来引用 Hook 到 DjangoCMS 的 url?

django url 参数包含带有命名空间的 url 之前

javascript - 向下滚动更改文本颜色不起作用?

javascript - 如何使用 jQuery 获取选定/事件选项卡的 href?

javascript - 基于 jQuery 中的垂直滚动值加载具有多个背景的长页面?

java - 如何使用ajax、json中返回的数组

python - 在 Django 中从 CSV 上传任何日期时间