我有这个 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) 我已经安装了jest,甚至安装了jest-cli,但仍然不能在命令行中使用jest。我可以像在package.json中一样进行npm测试,但是我在测试中遇到了问题,并且为了修复它,我需要访问'jest'命令(我需要执行jest --init并执行创建配置文件)。先感谢您!
Edit1:我正在使用React.JS
我在前端下载 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)