-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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