Is there a way to pass JSON objects to the front end of a web template if using the Django framework or Python in general?
For example, if I want to send an object t
Sure, just setup a view that returns JSON and make a request to it. Here's a simple example:
import json
from django.http import HttpResponse
from django.template import Template, Context
def ajax(request):
"""returns json response"""
return HttpResponse(json.dumps({'foo': 'bar'}), mimetype='application/json')
def index(request):
"""simple index page which uses jquery to make a single get request to /ajax, alerting the value of foo"""
t = Template("""