In my Django view, I am fetching results of an SQL query and rendering it on the index.html page of my web map. The POST request successfully returns the acreage calculated from the SQL query to the page. I am also attempting to display the geojson data from the SQL query on a Leaflet map. To achieve this, I am incorporating the geojson data in the Django template instead of using a JSONResponse, as I found it challenging to return both the rendered acreage to HTML and the JSONResponse simultaneously.
Here is a snippet from my HTML document, focusing on the relevant JavaScript:
<html>
<!-- HTML code here -->
</html>
And this is the relevant part of my views.py:
class HomePageView(TemplateView):
# Python code here
Upon console log the data received:
{ "type": "FeatureCollection", "features": [ { "type": "Feature", "geometry": { // Coordinates here }, "properties": { // Properties data here } } ] }
When trying to access the data:
var raw_data = '{{ data }}'
The output is:
{"type": "FeatureCollection", "features": [ {"type": "Feature", "geometry": { // Geometry data }, "properties": { // Properties data } }]}