2
Django creates a file called py views., in which I have the following function:
def carro_view(request,carro_slug=None):
evento = Evento.objects.filter(time = '11:28:30').distinct()
data = []
for x in evento:
data.append({
"latitude": x.lat.replace(',', '.'),
"longitude": x.lon.replace(',', '.'),
"title": x.carro
})
marker = {"markers": data }
return HttpResponse(json.dumps(marker), content_type="application/json")
I wonder how I could get this JSON in a JS file, I know there is a getJSON(url, function(data))
, but how could I use this to rescue the return of the function in py views.??
I do not understand the question. If you own in
urls.py
a routing associating a particular URL to that function, just use that URL ingetJSON
(probably using a second argument to choose the car, likegetJSON(url, { carro_slug:... }, function(data)
) and returning the already decoded Javascript object will be available in the parameterdata
. (P.S. Assuming you refer to$.getJSON
jQuery - I don’t know another)– mgibsonbr