Activate django-rest-framework and expose user model
This commit is contained in:
parent
f081c38209
commit
48431a4d84
7
authserver/authserver/api/serializers.py
Normal file
7
authserver/authserver/api/serializers.py
Normal file
|
@ -0,0 +1,7 @@
|
|||
from django.contrib.auth.models import User
|
||||
from rest_framework import serializers
|
||||
|
||||
class UserSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = User
|
||||
fields = ('username', 'email')
|
|
@ -1,3 +1,7 @@
|
|||
from django.shortcuts import render
|
||||
from django.contrib.auth.models import User
|
||||
from rest_framework import viewsets
|
||||
from authserver.api.serializers import UserSerializer
|
||||
|
||||
# Create your views here.
|
||||
class UserViewSet(viewsets.ModelViewSet):
|
||||
queryset = User.objects.all().order_by('-date_joined')
|
||||
serializer_class = UserSerializer
|
||||
|
|
|
@ -37,6 +37,7 @@ INSTALLED_APPS = [
|
|||
'django.contrib.sessions',
|
||||
'django.contrib.messages',
|
||||
'django.contrib.staticfiles',
|
||||
'rest_framework',
|
||||
]
|
||||
|
||||
MIDDLEWARE = [
|
||||
|
|
|
@ -16,6 +16,15 @@ Including another URLconf
|
|||
from django.contrib import admin
|
||||
from django.urls import path
|
||||
|
||||
from django.conf.urls import url, include
|
||||
from rest_framework import routers
|
||||
from authserver.api import views
|
||||
|
||||
router = routers.DefaultRouter()
|
||||
router.register(r'user', views.UserViewSet, 'user')
|
||||
|
||||
urlpatterns = [
|
||||
path('admin/', admin.site.urls),
|
||||
url(r'^', include(router.urls)),
|
||||
url(r'^admin/', admin.site.urls),
|
||||
url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework'))
|
||||
]
|
||||
|
|
Loading…
Reference in New Issue
Block a user