javascript - 用于 JS 和 JSON 文件/mimetype 扩展的 Python Flask ES6 导入
问题描述
我想对 JS/JSON 文件使用 ES6 导出/导入
// ui.js
import sampleData from '../data/sample-data.json';
export function initUI() {
console.log(sampleData)
}
我有一个烧瓶应用程序并在main.py
我添加了以下内容(我也尝试过切换顺序)。
mimetypes.add_type('application/json', ".json", strict=True)
mimetypes.add_type('application/javascript', ".js", strict=True)
这仅适用于 JS 文件。对于 JSON 导入,我收到以下错误。
Failed to load module script: The server responded with a non-JavaScript MIME type of "application/json". Strict MIME type checking is enforced for module scripts per HTML spec.
我的想法是因为json
有前缀js
。因此,所有json
导入都被视为.js
文件。
我怎样才能解决这个问题?
解决方案
推荐阅读
- android - android webview覆盖工具栏
- ruby-on-rails - 在 HTML 标签中动态呈现数组元素的索引值的语法
- android - Android Studio 的调试器问题
- opencart - Opencart :: 是否可以在没有 VQMOD 或 OCMOD 的情况下创建更改标头之类的事件?
- python - 你能解释一下这个python代码吗?
- javascript - 定义自定义 D3 符号
- scala - 在 Ubuntu 18.04 上安装 sbt 时出错:`gpg: keyserver receive failed: Invalid argument`
- javascript - 如何在不影响性能的情况下将大量数据加载到数据表中
- wildcard - AEM 6.4:在过滤器定义中使用通配符
- julia - Julia 的微分方程步长控制