A Simple json renderer for django.
Project description
A Simple json renderer for django.
Install
pip install django-json-renderer
Api
JsonResponse
Native Django JsonResponse (or it’s polyfill).
ModelJSONEncoder
Inherit from DjangoJSONEncoder, extends the parser of QuerySet (using list(queryset.values())) and Models (using model_to_dict).
render_json(encoder=ModelJSONEncoder, safe=True, **kwargs)
Return the decorator that convert json-serializable to JsonResponse (using ModelJSONEncoder as default). encoder and safe params has the same meaning as Django JsonResponse.
Example
from django.db import models
from django_json_encoder import render_json
class Person(models.Model):
first_name = models.CharField(max_length=30)
last_name = models.CharField(max_length=30)
@render_json()
def get_first_person(request):
return Person.objects.all().first()
## `safe` params
@render_json(safe=False)
def get_all_person(request):
return Person.objects.all()
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Close
Hashes for django-json-renderer-0.1.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | f4a90e0682e02de185cc2a68a1dd3282bf7f9c429187d5d66ca173fc38fe9dbf |
|
MD5 | ef4c73535dbe9f793eb7d04f4c21db38 |
|
BLAKE2b-256 | 1e00af0440f92507d37a31cf8f0a4c8982b546eac706fcb808ae2282ce7fd0e3 |