Skip to content

Instantly share code, notes, and snippets.

@ntoll
Created February 14, 2020 15:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ntoll/5161942a5e6f08afc10dda14712e4f2e to your computer and use it in GitHub Desktop.
Save ntoll/5161942a5e6f08afc10dda14712e4f2e to your computer and use it in GitHub Desktop.
from django.conf.urls import url, include
from django.contrib.auth.models import User
from rest_framework import routers, serializers, viewsets
# Serializers define the API representation.
class UserSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = User
fields = ["url", "username", "email", "is_staff", ]
class UserViewSet(viewsets.ModelViewSet):
queryset = User.objects.all()
serializer_class = UserSerializer
router = routers.DefaultRouter()
router.register(r"users", UserViewSet)
urlpatterns = [
url(r"^", include(router.urls)),
url(r"^api-auth/", include("rest_framework.urls", namespace="rest_framework")),
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment