小编Ger*_*kov的帖子

Python Flask - 错误:“无法加载模块脚本。强制执行严格的 MIME 类型检查”。适用于生产环境,不适用于本地服务器

我有这个 html 文件:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <link
        rel="stylesheet"
        href="../../../static/css/style.css"
        type="text/css" />
    <link
        rel="stylesheet"
        href="../../../static/css/user_header.css"
        type="text/css" />

    <!--suppress HtmlUnknownTarget -->
    <link rel="shortcut icon" href="/favicon.png">

    <script type="module" src="../../../static/js/node_connect.js" ></script>  <-- Error
    <script src="../../../static/lib/jquery.min.js"></script>
    <script src="../../../static/lib/selfserve.js"></script>   

</head>
Run Code Online (Sandbox Code Playgroud)

有问题的部分是node_connect.js文件。本地启动Flask web工具(Python 3.7.2)时,打开页面时控制台报如下错误:

Failed to load module script: The server responded with a non-JavaScript MIME type of "text/plain".
Strict MIME type checking is enforced for module scripts per HTML spec.
Run Code Online (Sandbox Code Playgroud)

检查标题:

Content-Type: text/plain; charset=utf-8
Run Code Online (Sandbox Code Playgroud)

然而,在生产中(当通过 Gunicorn 启动时)它给出了:

Content-Type: application/javascript; charset=utf-8 …
Run Code Online (Sandbox Code Playgroud)

html javascript python http-headers flask

9
推荐指数
2
解决办法
9303
查看次数

玩笑错误:“玩笑”未被识别为内部或外部命令,可操作程序或批处理文件

我已经安装了jest,甚至安装了jest-cli,但仍然不能在命令行中使用jest。我可以像在package.json中一样进行npm测试,但是我在测试中遇到了问题,并且为了修复它,我需要访问'jest'命令(我需要执行jest --init并执行创建配置文件)。先感谢您!

Edit1:我正在使用React.JS

testing babel reactjs jestjs

7
推荐指数
3
解决办法
4684
查看次数

从 API 响应下载 excel 文件(Vue.JS - 前端,Flask 后端)

我在前端下载 Excel 文件时遇到一些困难,该文件是通过 API 响应获得的,该响应是我对 Flask 后端进行的。

这是我到目前为止所拥有的:

烧瓶(后端)

...
generator.generate_excel_report()
return send_file(
    generator.get_excel_report(), # returns location to generated file
    mimetype=sc.CONTENT_TYPE_EXCEL, # application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
    as_attachment=True
)
...
Run Code Online (Sandbox Code Playgroud)

我已经通过 Postman 测试了这一点,我可以从那里下载此 Excel 报告,一切似乎都正常。

Vue.JS(前端)

在这里,我向 Flask 后端发出请求,后端返回正文中的文件:

    /**
     * Download Excel version of the report
     */
    downloadExcelReport(data) {
      SERVICE.post(
      `/api/v1/project/${this.projectNumber}/${this.variantName}/${this.buildNumber}/report/excel`, {
            responseType: 'arraybuffer'
          }).then((response) => getExcelReport(response.data))
     },
Run Code Online (Sandbox Code Playgroud)

这里的getExcelReport函数:

/**
 * Make a POST request to the back-end that will generate an Excel sheet
 * for the project, and return it.
 */ …
Run Code Online (Sandbox Code Playgroud)

rest excel flask vue.js axios

1
推荐指数
1
解决办法
2960
查看次数

标签 统计

flask ×2

axios ×1

babel ×1

excel ×1

html ×1

http-headers ×1

javascript ×1

jestjs ×1

python ×1

reactjs ×1

rest ×1

testing ×1

vue.js ×1