Closed thisAKcode closed 2 years ago
The FastAPI side is correct and locs
has data in map.html and it renders in the browser. But I don't think you can pass data from map.html into loci.js, so what about moving the function calls into map.html so you can actually embed variables, e.g.:
Thanks for review. I'll try to work it out.
The FastAPI side is correct and
locs
has data in map.html and it renders in the browser. But I don't think you can pass data from map.html into loci.js, so what about moving the function calls into map.html so you can actually embed variables, e.g.:
make sense at the same time I'll have quite big js code file and it'll be hard to re use in another app. So I try to grab data from api and pass it to js, which almost works now:
@app.get("/map2/", response_class=HTMLResponse)
async def _map(
request:Request,
db:Session = Depends(get_db)
):
locations1 = db.query(model.ArtItem).all() # []
print(type(locations1[0]))
#locs = json.dumps({"message": "fine"}, indent = 4)
json_object = json.dumps({"message": "fine"}, indent = 4)
return json_object
Hey, I was not able to send data within
content
while usingTemplateResponse
to the js script in map.htmltemplates.TemplateResponse("map.html", context)
I tried to add CORSmiddleware thing to grab data from api directly and then send int ot map2.html. maybe I keep this and remove TemplateResponse solution? Meanwhile i'll keep both in order to learn how templateresponse works.