Displaying existing crimes on our map
Now, the user can add new crimes to our crime database, but we want the map to display crimes that are already added as well. To achieve this, whenever the page is loaded, our app needs to make a call to the database to get the latest crime data. We then need to pass this data to our template file, loop through each crime, and place a marker in the correct place on the map.
Now, our data is stored in a MySQL database. We will access it using Python on the server side, and we want to display it using JavaScript on the client side; so, we'll need to spend a bit of time on converting our data to the appropriate format. When we access the data through our Python pymysql
driver, we will receive it as a tuple. To ...
Get Flask By Example now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.