Skip to content

Instantly share code, notes, and snippets.

@mjumbewu
Forked from ptone/gist:3490967
Created September 8, 2012 17:20
Show Gist options
  • Save mjumbewu/3677442 to your computer and use it in GitHub Desktop.
Save mjumbewu/3677442 to your computer and use it in GitHub Desktop.
Using djangorestframework2 to get JSON given just a resource outside of a view
from djangorestframework.renderers import JSONRenderer
from colorpicks.serializer import ColorSerializer
# NOTE: Resources are nominally much less present in the
# restframework2 branch. You use Serializers directly
# to achieve the same thing.
obj = ...
serializer = ColorSerializer(instance=obj)
data = serializer.data
jsonr = JSONRenderer()
json_string = jsonr.render(data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment