Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Django rest framework in 20 minuten

775 views

Published on

Slides from a mini talk given at Python User Group Meeting in Bonn in April 2015

Published in: Technology
  • Login to see the comments

  • Be the first to like this

Django rest framework in 20 minuten

  1. 1. DJANGO REST FRAMEWORK IN 20 MINUTEN   ;) Python User Group Bonn, 16. April 2015 Andi Albrecht
  2. 2. "Django REST framework is a powerful and flexible toolkit that makes it easy to build Web APIs." http://www.django-rest-framework.org/
  3. 3. BATTERIES INCLUDED API Browser Serialisierung von Daten und Django-Models automatische View-Generierung Sicherheitsmechanismen Validierung, sinnvolle HTTP-Status-Codes, URL-Muster, etc. Doku, Doku, Doku...
  4. 4. HOW IT WORKS: SERIALIZERS from django.contrib.auth.models import User, Group from rest_framework import serializers class UserSerializer(serializers.HyperlinkedModelSerializer):     class Meta:         model = User         fields = ('url', 'username', 'email', 'groups') class GroupSerializer(serializers.HyperlinkedModelSerializer):     class Meta:         model = Group         fields = ('url', 'name')
  5. 5. HOW IT WORKS: VIEWS from django.contrib.auth.models import User, Group from rest_framework import viewsets from quickstart.serializers import UserSerializer, GroupSerializer class UserViewSet(viewsets.ModelViewSet):     """API endpoint that allows users to be viewed or edited."""     queryset = User.objects.all()     serializer_class = UserSerializer class GroupViewSet(viewsets.ModelViewSet):     """API endpoint that allows groups to be viewed or edited."""     queryset = Group.objects.all()     serializer_class = GroupSerializer
  6. 6. HOW IT WORKS: ROUTER from django.conf.urls import url, include from rest_framework import routers from tutorial.quickstart import views router = routers.DefaultRouter() router.register(r'users', views.UserViewSet) router.register(r'groups', views.GroupViewSet) # Wire up our API using automatic URL routing. # Additionally, we include login URLs for the browsable API. urlpatterns = [     url(r'^', include(router.urls)),     url(r'^api­auth/', include('rest_framework.urls')) ]
  7. 7. DONE. (Demo)

×