An overview of history and current state of REST support in Django ecosystem, including what's great in Django Rest Framework but also when it might be a good idea to use something else.
Simple REST withDjangoSenko Rašić, Dobar Kod
View Slide
Previously in Django…Django Piston!TastyPie!roll your own
Do you have a minute?!I’d like to talk to you about our Lord and Saviour
Django REST FrameworkBrowsable API!Authentication!Serialization!Docs & community
..meanwhile in Django..from django.http import JSONResponsefrom django.core import serializers!!def books_list(request):qs = Book.objects.all()return JSONResponse(qs.values())!!def book_detail(request, book_id):book = get_object_or_404(Book, id=book_id)dct = serializers.serialize(‘python’, [book])return JSONResponse(dct)
DjangoRestlessfrom restless.views import Endpointfrom restless.models import serialize!class BookList(Endpoint):def get(self, request):return serialize(Book.objects.all())!class BookDetail(Endpoint):def get(self, request, book_id):book = get_object_or_404(Book, id=book_id)return serialize(book)
model viewsfrom restless.modelviews import *!!class BookList(ListEndpoint):model = Book!class BookDetail(DetailEndpoint):model = Book
custom serializationfrom restless.models import serialize!!def my_ordinary_view(request):book = Book.objects.all()return serialize(book, fields=[‘title’,(‘author’, {fields=[‘name’, ‘address’]}),(‘publisher’, {fields=[‘name’, ‘address’]}),‘summary’,(’n_comments’,lambda x: x.comments.Count())])
..and now for the conclusionDRF is awesome!but!Use the right tool for the job