I have a query set whose objects I’d like to use to populate a template. One view I have ends with
return render_to_response('entry.json', {'entry_list':r}, mimetype="application/json; charset=utf-8")
However I’d like to be able to serialise to json with a template like this without having to return a HTTPResponse. In pseudocode, this might be:
render('entry.json', {'entry_list':r}) #returns a string with the template entry.json
Is this possible? If so, how?
Django provides a built in shortcut for this.
https://docs.djangoproject.com/en/dev/ref/templates/api/#the-render-to-string-shortcut
I don’t quite understand what you are trying to accomplish, But you can just return JSON as your HTTPResponse. You can serialize objects to jason and return it without the use of any template.