我正在尝试将数据加载到我的flask页面中,并将其记录到控制台日志中,但是我不断得到下面的错误
VM165:1 Uncaught ReferenceError: data is not defined
at <anonymous>:1:13
这些是my.py和.html中的代码片段
import os
from flask import Flask, render_template, jsonify, request, redirect
import json
app = Flask(__name__)
@app.route("/")
def home():
json_file = open("/Users/-------/Documents/GitHub/Geospatial-Opportunities-for-Supermarkets/supermarket_locations/longos_locations.json", "r", encoding ="utf-8")
data = json.load(json_file)
json_file.close
return render_template("index.html", data = data)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Supermarkets in Toronto</title>
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.0.0-rc.3/dist/leaflet.css" />
<link rel="stylesheet" type="text/css" href="static/css/style.css">
<script> var data = '{{data}}'; </script>
</head>
看起来我有2个index.html文件,但我用错了
相关问题 更多 >
编程相关推荐