SlideShare a Scribd company logo
Django Rest Framework
Tips and Tricks
Xavier ORDOQUY
@linovia_net
Freelance!
(since 2004) Python
Django!
(Backend)
Raven maintainer!
(Sentry client)
Former!
PyGTK!
contributor
Various!
pull requests
irc: Linovia
@linovia_net
Expertise
Dev
Reminder
• It is Django !
!
• It is Python !
Fully featured
• Serializers
• ModelSerializers
• Parsers
• Renderers
• Authentication
• Permission
• Throttling
• Routers
• Views
• ViewSets
• Filtering
• Testing
• Pagination
from rest_framework.decorators import api_view!
 !
@api_view(['GET'])!
def hello_world(request):!
return Response({"message": "Hello, world!"})
but loosely coupled
Authentication
Content negotiation
Serializers
Generic views
Customizable web interface
Debug toolbar
pre/post save
class MyCreateView(CreateAPIView):!
model = models.MyModel!
serializer_class = serializers.MySerializer!
!
def post_save(self, obj, created):!
if created:!
obj.reviewers = [user1, user2]!
Class based views
class MyMixin(object):!
model = models.MyModel!
serializer_class = serializers.MySerializer!
!
!
class MyCreateView(MyMixin, CreateAPIView):!
pass!
• MRO: mixins are on the left side
# views.py!
class UserViewSet(viewsets.ModelViewSet):!
queryset = User.objects.all()!
serializer_class = UserSerializer!
!
# urls.py!
router = DefaultRouter()!
router.register(r'users', views.UserViewSet)!
!
urlpatterns = patterns('',!
url(r'^', include(router.urls)),!
)!
Viewsets & routers
Nice to get started but optional
Auth / Permissions
• Auth are for knowing who you are
!
• Permissions are to grant you access
Testing Utilities
• APIRequestFactory + format !
• force_authenticate
• APIClient
response = self.client.get('/users/4/')!
self.assertEqual(response.data,!
{'id': 4, 'username': 'lauren'})!
Performances
• Fast to prototype
• Easy to tune
• Django performance tips also applies !
Tempsemms
0
10
20
30
40
50
60
70
80
90
100
110
120
130
140
Full stack Serialisation Redis Content nego Middleware HttpResponse
Database lookup Redis lookup Serialization
Django request/response API view Response rendering
Django rest framework   tips and tricks
• Django Rest Framwork Optimization:

http://dabapps.com/blog/api-performance-profiling-django-rest-framework/

More Related Content

What's hot (20)

PDF
Capybara with Rspec
Omnia Helmi
 
PPT
Introduction To Ruby Watir (Web Application Testing In Ruby)
Mindfire Solutions
 
PDF
Avoiding Common Pitfalls in Ember.js
Alex Speller
 
PPTX
Get Django, Get Hired - An opinionated guide to getting the best job, for the...
Marcel Chastain
 
PDF
APIs: A Better Alternative to Page Objects
Sauce Labs
 
PDF
Unlocking the Magical Powers of WP_Query
Dustin Filippini
 
PDF
Writing Software not Code with Cucumber
Ben Mabey
 
PPTX
Capybara + RSpec - ruby dsl-based web ui qa automation
COMAQA.BY
 
PPT
Automated Testing With Watir
Timothy Fisher
 
PDF
Introduction To Web Application Testing
Ynon Perek
 
PDF
Apigility – Lightning Fast API Development - OSSCamp 2014
OSSCube
 
PPTX
Best Practices for Building WordPress Applications
Taylor Lovett
 
PDF
Best Practices for WordPress
Taylor Lovett
 
DOC
Selenium Automation Using Ruby
Kumari Warsha Goel
 
PDF
You Got React.js in My PHP
Taylor Lovett
 
PDF
Consuming REST services with ActiveResource
Wolfram Arnold
 
PDF
The Many Ways to Test Your React App
All Things Open
 
KEY
Impression of Rails 3
Kosuke Matsuda
 
PPTX
Saving Time with WP-CLI
Taylor Lovett
 
PDF
Modernizing WordPress Search with Elasticsearch
Taylor Lovett
 
Capybara with Rspec
Omnia Helmi
 
Introduction To Ruby Watir (Web Application Testing In Ruby)
Mindfire Solutions
 
Avoiding Common Pitfalls in Ember.js
Alex Speller
 
Get Django, Get Hired - An opinionated guide to getting the best job, for the...
Marcel Chastain
 
APIs: A Better Alternative to Page Objects
Sauce Labs
 
Unlocking the Magical Powers of WP_Query
Dustin Filippini
 
Writing Software not Code with Cucumber
Ben Mabey
 
Capybara + RSpec - ruby dsl-based web ui qa automation
COMAQA.BY
 
Automated Testing With Watir
Timothy Fisher
 
Introduction To Web Application Testing
Ynon Perek
 
Apigility – Lightning Fast API Development - OSSCamp 2014
OSSCube
 
Best Practices for Building WordPress Applications
Taylor Lovett
 
Best Practices for WordPress
Taylor Lovett
 
Selenium Automation Using Ruby
Kumari Warsha Goel
 
You Got React.js in My PHP
Taylor Lovett
 
Consuming REST services with ActiveResource
Wolfram Arnold
 
The Many Ways to Test Your React App
All Things Open
 
Impression of Rails 3
Kosuke Matsuda
 
Saving Time with WP-CLI
Taylor Lovett
 
Modernizing WordPress Search with Elasticsearch
Taylor Lovett
 

Viewers also liked (20)

PPTX
REST Easy with Django-Rest-Framework
Marcel Chastain
 
PDF
Django REST Framework
Load Impact
 
PDF
Djangocon 2014 - Django REST Framework - So Easy You Can Learn it in 25 Minutes
Nina Zakharenko
 
PDF
Create responsive websites with Django, REST and AngularJS
Hannes Hapke
 
PDF
Djangocon 2014 angular + django
Nina Zakharenko
 
PDF
Django Rest Framework - Building a Web API
Marcos Pereira
 
PDF
DJANGO-REST-FRAMEWORK: AWESOME WEB-BROWSABLE WEB APIS
Fernando Rocha
 
PDF
Introduction to AngularJS
Jamal Sinclair O'Garro
 
PDF
Django Uni-Form
Daniel Greenfeld
 
PDF
The django book - Chap10 : Advanced Models
Spin Lai
 
PDF
Building an API with Django and Django REST Framework
Christopher Foresman
 
PDF
Boas práticas de django
Filipe Ximenes
 
PDF
Dynamic Models with Django
schacki
 
PPTX
Парсер: что? зачем? как?
STEP Computer Academy (Zaporozhye)
 
PPTX
django-and-postgresql
Oleg Churkin
 
PDF
Django Rest Framework and React and Redux, Oh My!
Eric Palakovich Carr
 
PDF
Framework Battle: Django vs Flask vs Chalice
STEP Computer Academy (Zaporozhye)
 
PDF
Python RESTful webservices with Python: Flask and Django solutions
Solution4Future
 
PDF
Building Automated REST APIs with Python
Jeff Knupp
 
PDF
Introduction To Single Page Application
KMS Technology
 
REST Easy with Django-Rest-Framework
Marcel Chastain
 
Django REST Framework
Load Impact
 
Djangocon 2014 - Django REST Framework - So Easy You Can Learn it in 25 Minutes
Nina Zakharenko
 
Create responsive websites with Django, REST and AngularJS
Hannes Hapke
 
Djangocon 2014 angular + django
Nina Zakharenko
 
Django Rest Framework - Building a Web API
Marcos Pereira
 
DJANGO-REST-FRAMEWORK: AWESOME WEB-BROWSABLE WEB APIS
Fernando Rocha
 
Introduction to AngularJS
Jamal Sinclair O'Garro
 
Django Uni-Form
Daniel Greenfeld
 
The django book - Chap10 : Advanced Models
Spin Lai
 
Building an API with Django and Django REST Framework
Christopher Foresman
 
Boas práticas de django
Filipe Ximenes
 
Dynamic Models with Django
schacki
 
Парсер: что? зачем? как?
STEP Computer Academy (Zaporozhye)
 
django-and-postgresql
Oleg Churkin
 
Django Rest Framework and React and Redux, Oh My!
Eric Palakovich Carr
 
Framework Battle: Django vs Flask vs Chalice
STEP Computer Academy (Zaporozhye)
 
Python RESTful webservices with Python: Flask and Django solutions
Solution4Future
 
Building Automated REST APIs with Python
Jeff Knupp
 
Introduction To Single Page Application
KMS Technology
 
Ad

Similar to Django rest framework tips and tricks (20)

PPTX
Write an API for Almost Anything: The Amazing Power and Flexibility of Django...
Caktus Group
 
PDF
Django Rest Framework - tips & trick
Luca Zacchetti
 
PDF
Easy Step-by-Step Guide to Develop REST APIs with Django REST Framework
Inexture Solutions
 
PPTX
React django
Heber Silva
 
PDF
Rest api with Python
Santosh Ghimire
 
PPTX
Introduction to Django Rest Framework
bangaloredjangousergroup
 
PPTX
Drf
Ibrahim Kasim
 
PDF
Reliable Python REST API (by Volodymyr Hotsyk) - Web Back-End Tech Hangout - ...
Innovecs
 
PPTX
Documenting an API written in Django Rest Framework
smirolo
 
PPTX
Django REST Framework 2022fffffffff.pptx
ThirzaAhmadTsaqif
 
PDF
Implement nested serializers in the Django rest framework
Ritika
 
PPTX
Django with REST API Online Training - NareshIT
avinashnit
 
PPTX
Building REST APIs with Django
Byron Dover
 
PDF
Django Rest Framework + React
wsvincent
 
PDF
DRF React
wsvincent
 
PDF
10 things you should know about django
Adieu
 
PPTX
1Uso de DRF (Django Rest Framework).pptx
danielfmd1
 
PDF
Django Restful Web Services Gaston C Hillar
suilahvrieze
 
PDF
FastAPI - Rest Architecture - in english.pdf
inigraha
 
PPTX
Django rest framework
Blank Chen
 
Write an API for Almost Anything: The Amazing Power and Flexibility of Django...
Caktus Group
 
Django Rest Framework - tips & trick
Luca Zacchetti
 
Easy Step-by-Step Guide to Develop REST APIs with Django REST Framework
Inexture Solutions
 
React django
Heber Silva
 
Rest api with Python
Santosh Ghimire
 
Introduction to Django Rest Framework
bangaloredjangousergroup
 
Reliable Python REST API (by Volodymyr Hotsyk) - Web Back-End Tech Hangout - ...
Innovecs
 
Documenting an API written in Django Rest Framework
smirolo
 
Django REST Framework 2022fffffffff.pptx
ThirzaAhmadTsaqif
 
Implement nested serializers in the Django rest framework
Ritika
 
Django with REST API Online Training - NareshIT
avinashnit
 
Building REST APIs with Django
Byron Dover
 
Django Rest Framework + React
wsvincent
 
DRF React
wsvincent
 
10 things you should know about django
Adieu
 
1Uso de DRF (Django Rest Framework).pptx
danielfmd1
 
Django Restful Web Services Gaston C Hillar
suilahvrieze
 
FastAPI - Rest Architecture - in english.pdf
inigraha
 
Django rest framework
Blank Chen
 
Ad

Recently uploaded (20)

PPTX
Human Resources Information System (HRIS)
Amity University, Patna
 
PPTX
Comprehensive Guide: Shoviv Exchange to Office 365 Migration Tool 2025
Shoviv Software
 
PDF
Understanding the Need for Systemic Change in Open Source Through Intersectio...
Imma Valls Bernaus
 
PDF
Executive Business Intelligence Dashboards
vandeslie24
 
PDF
GetOnCRM Speeds Up Agentforce 3 Deployment for Enterprise AI Wins.pdf
GetOnCRM Solutions
 
PDF
Alarm in Android-Scheduling Timed Tasks Using AlarmManager in Android.pdf
Nabin Dhakal
 
PPTX
An Introduction to ZAP by Checkmarx - Official Version
Simon Bennetts
 
PPTX
Fundamentals_of_Microservices_Architecture.pptx
MuhammadUzair504018
 
PDF
Alexander Marshalov - How to use AI Assistants with your Monitoring system Q2...
VictoriaMetrics
 
PPTX
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pptx
Varsha Nayak
 
PDF
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
PPTX
MiniTool Power Data Recovery Full Crack Latest 2025
muhammadgurbazkhan
 
PDF
Digger Solo: Semantic search and maps for your local files
seanpedersen96
 
PPTX
MailsDaddy Outlook OST to PST converter.pptx
abhishekdutt366
 
PDF
Powering GIS with FME and VertiGIS - Peak of Data & AI 2025
Safe Software
 
PPTX
Equipment Management Software BIS Safety UK.pptx
BIS Safety Software
 
PPTX
Engineering the Java Web Application (MVC)
abhishekoza1981
 
PPTX
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
PDF
Beyond Binaries: Understanding Diversity and Allyship in a Global Workplace -...
Imma Valls Bernaus
 
PDF
Mobile CMMS Solutions Empowering the Frontline Workforce
CryotosCMMSSoftware
 
Human Resources Information System (HRIS)
Amity University, Patna
 
Comprehensive Guide: Shoviv Exchange to Office 365 Migration Tool 2025
Shoviv Software
 
Understanding the Need for Systemic Change in Open Source Through Intersectio...
Imma Valls Bernaus
 
Executive Business Intelligence Dashboards
vandeslie24
 
GetOnCRM Speeds Up Agentforce 3 Deployment for Enterprise AI Wins.pdf
GetOnCRM Solutions
 
Alarm in Android-Scheduling Timed Tasks Using AlarmManager in Android.pdf
Nabin Dhakal
 
An Introduction to ZAP by Checkmarx - Official Version
Simon Bennetts
 
Fundamentals_of_Microservices_Architecture.pptx
MuhammadUzair504018
 
Alexander Marshalov - How to use AI Assistants with your Monitoring system Q2...
VictoriaMetrics
 
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pptx
Varsha Nayak
 
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
MiniTool Power Data Recovery Full Crack Latest 2025
muhammadgurbazkhan
 
Digger Solo: Semantic search and maps for your local files
seanpedersen96
 
MailsDaddy Outlook OST to PST converter.pptx
abhishekdutt366
 
Powering GIS with FME and VertiGIS - Peak of Data & AI 2025
Safe Software
 
Equipment Management Software BIS Safety UK.pptx
BIS Safety Software
 
Engineering the Java Web Application (MVC)
abhishekoza1981
 
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
Beyond Binaries: Understanding Diversity and Allyship in a Global Workplace -...
Imma Valls Bernaus
 
Mobile CMMS Solutions Empowering the Frontline Workforce
CryotosCMMSSoftware
 

Django rest framework tips and tricks