Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does this work using django.http.JsonResponse? #41

Open
lucas-bremond opened this issue Apr 10, 2018 · 0 comments
Open

Does this work using django.http.JsonResponse? #41

lucas-bremond opened this issue Apr 10, 2018 · 0 comments

Comments

@lucas-bremond
Copy link

lucas-bremond commented Apr 10, 2018

Hi there! Very nice tool, thanks!

Would this this library also work with Django's JsonResponse?

According to Django's doc:
https://docs.djangoproject.com/en/2.0/ref/request-response/#jsonresponse-objects
an encoder can be set.

response = JsonResponse(data, encoder=MyJSONEncoder)

For example, in views.py:

from django.http import JsonResponse
from .models import User
from .serializers import UserSerializer

def user_view(request):

    user = User.objects.get(pk=1)

    return JsonResponse(UserSerializer(user).data, encoder=CamelCaseJSONEncoder)

That'd be pretty elegant... ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants