Skip to content

Instantly share code, notes, and snippets.

@robrocker7
Created December 27, 2012 17:46
Show Gist options
  • Save robrocker7/4390295 to your computer and use it in GitHub Desktop.
Save robrocker7/4390295 to your computer and use it in GitHub Desktop.
def example_view(request, id):
obj = Model.objects.get(id=id)
context = {}
context['obj'] = obj
reponse_html = render_to_string('path/to/template.html', context, context_instance=RequestContext(request))
if request.is_ajax():
context['html'] = response_html
return HttpResponse(json.dumps(context), mimetype="application/json")
return HttpResponse(response_html)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment