mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-07-27 00:19:53 +03:00
Update README.md
This commit is contained in:
parent
8b2ccccbe5
commit
bbcaa2b158
|
@ -90,9 +90,10 @@ Startup up a new project like so...
|
||||||
Now edit the `example/urls.py` module in your project:
|
Now edit the `example/urls.py` module in your project:
|
||||||
|
|
||||||
```python
|
```python
|
||||||
from django.urls import path, include
|
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from rest_framework import serializers, viewsets, routers
|
from django.urls import include, path
|
||||||
|
from rest_framework import routers, serializers, viewsets
|
||||||
|
|
||||||
|
|
||||||
# Serializers define the API representation.
|
# Serializers define the API representation.
|
||||||
class UserSerializer(serializers.HyperlinkedModelSerializer):
|
class UserSerializer(serializers.HyperlinkedModelSerializer):
|
||||||
|
@ -101,7 +102,7 @@ class UserSerializer(serializers.HyperlinkedModelSerializer):
|
||||||
fields = ['url', 'username', 'email', 'is_staff']
|
fields = ['url', 'username', 'email', 'is_staff']
|
||||||
|
|
||||||
|
|
||||||
# ViewSets define the view behavior.
|
# View sets define the view behavior.
|
||||||
class UserViewSet(viewsets.ModelViewSet):
|
class UserViewSet(viewsets.ModelViewSet):
|
||||||
queryset = User.objects.all()
|
queryset = User.objects.all()
|
||||||
serializer_class = UserSerializer
|
serializer_class = UserSerializer
|
||||||
|
@ -111,7 +112,6 @@ class UserViewSet(viewsets.ModelViewSet):
|
||||||
router = routers.DefaultRouter()
|
router = routers.DefaultRouter()
|
||||||
router.register(r'users', UserViewSet)
|
router.register(r'users', UserViewSet)
|
||||||
|
|
||||||
|
|
||||||
# Wire up our API using automatic URL routing.
|
# Wire up our API using automatic URL routing.
|
||||||
# Additionally, we include login URLs for the browsable API.
|
# Additionally, we include login URLs for the browsable API.
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
|
|
Loading…
Reference in New Issue
Block a user