为何script标签无法加载world.js?Flask项目报错排查
加载world.js文件失败,出现404错误与ReferenceError
问题说明
我尝试在HTML页面中加载world.js文件(该文件存储各国坐标的GeoJSON数据),但加载失败。我参照的教程中将<script>标签放在<html>标签外也能正常运行,但我的代码运行时出现报错。
HTML代码
<!DOCTYPE html> <html lang="en"> <head> ... <script src = "../world.js"></script> ... </head> <body>...</body> </html> <script src="https://unpkg.com/leaflet@1.8.0/dist/leaflet.js" integrity="sha512-BB3hKbKWOc9Ez/TAwyWxNXeoV9c1v6FIeYiBieIWkpLjauysF18NzgR1MBNBXf8/KABdlkX68nAhlwcDFLGPCQ==" crossorigin=""></script> <script> ... L.geoJSON(countries).addTo(map); // (index):64:15 </script>
运行错误
Failed to load resource: the server responded with a status of 404 (NOT FOUND) (index):64 Uncaught ReferenceError: countries is not defined at (index):64:15
注:悬停在script的src链接并点击时,能打开正确的文件,但应用运行时仍出现上述错误。
补充信息
- 目录结构见指定截图
- Flask项目的app.py代码如下:
from flask import Flask, render_template app = Flask(__name__) @app.route("/") def home(): return render_template('index_2.html')
内容的提问来源于stack exchange,提问作者Parth Gupta
相关产品推荐
相关产品推荐

