Solution 1 :

Looks like I had 2 index.html files and I was using the wrong one

Problem :

I am trying load data into my flask page, and console log it, however I keep getting the below error

VM165:1 Uncaught ReferenceError: data is not defined
    at <anonymous>:1:13

These are the code snippets from my .py and .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/[email protected]/dist/leaflet.css" />
  <link rel="stylesheet" type="text/css" href="static/css/style.css">
  <script> var data = '{{data}}'; </script>
</head>

Comments

Comment posted by sopython.com/canon/93/…

sopython.com/canon/93/…

Comment posted by mechanical_meat

Don’t put the quotes around it. Are you doing just

Comment posted by mrEvgenX

Just now I tried to reproduce the issue, but the code snippets you have shown worked well.

Comment posted by mechanical_meat

Yes, @mrEvgenX this is working for me too.

Comment posted by leaflet map

if you don’t use

By