1pip install djangorestframework
2pip install markdown # Markdown support for the browsable API.
3pip install django-filter # Filtering support
1pip install djangorestframework
2pip install markdown # Markdown support for the browsable API.
3pip install django-filter # Filtering support
1from django.contrib.auth.models import User, Group
2from rest_framework import serializers
3
4
5class UserSerializer(serializers.HyperlinkedModelSerializer):
6 class Meta:
7 model = User
8 fields = ['url', 'username', 'email', 'groups']
9
10
11class GroupSerializer(serializers.HyperlinkedModelSerializer):
12 class Meta:
13 model = Group
14 fields = ['url', 'name']
1from django.urls import include, path
2from rest_framework import routers
3from tutorial.quickstart import views
4
5router = routers.DefaultRouter()
6router.register(r'users', views.UserViewSet)
7router.register(r'groups', views.GroupViewSet)
8
9# Wire up our API using automatic URL routing.
10# Additionally, we include login URLs for the browsable API.
11urlpatterns = [
12 path('', include(router.urls)),
13 path('api-auth/', include('rest_framework.urls', namespace='rest_framework'))
14]