Django REST FRAMEWORK Tutorial の 빠른 시작 프로젝트의 API 環境をdocker-compose 그리고 立ち上げる
8657 단어 djangorestframework
8002 で動いている
startapp 그리고 project の中で 빠른 시작 앱을 만드세요
https://www.django-rest-framework.org/tutorial/quickstart/#project-setup
빠른 시작 페이지를 살펴보세요
rest4/rest4/の프로제크트の中には作れず
rest4/quickstart/그렇죠?
docker-compose run web django-admin startapp quickstart
Starting rest4_db_1 ... done
Creating rest4_web_run ... done
django-admin startapp quickstart
で quickstart 이라고 하는 이름을 앞세워 실행합니다.======
이주하다
docker-compose run web python manage.py migrate
Creating rest4_web_run ... done
Operations to perform:
Apply all migrations: admin, auth, contenttypes, sessions
Running migrations:
No migrations to apply.
DB の初期化完了.
=====
슈퍼 유저 생성 でスーパーユーザーを作る
dc run web \
python manage.py createsuperuser \
--email [email protected] --username admin
Creating rest4_web_run ... done
Password:
Password (again):
Superuser created successfully.
=====
シリアライザ、뷰、URL を作る
serializers.py
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']
ここは츄트리알통리
=============
views.py
from django.contrib.auth.models import User, Group
from rest_framework import viewsets
from rest_framework import permissions
from quickstart.serializers import UserSerializer, GroupSerializer
class UserViewSet(viewsets.ModelViewSet):
"""
API endpoint that allows users to be viewed or edited.
"""
queryset = User.objects.all().order_by('-date_joined')
serializer_class = UserSerializer
permission_classes = [permissions.IsAuthenticated]
class GroupViewSet(viewsets.ModelViewSet):
"""
API endpoint that allows groups to be viewed or edited.
"""
queryset = Group.objects.all()
serializer_class = GroupSerializer
permission_classes = [permissions.IsAuthenticated]
츄트리알의 산풀로
from tutorial.quickstart.serializers
になっているが,
from quickstart.serializers
にする
==========
urls.py
from django.urls import include, path
from rest_framework import routers
from 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 = [
path('', include(router.urls)),
path('api-auth/', include('rest_framework.urls', namespace='rest_framework'))
]
同様に
=====
~째
これで 작곡 で動かせる
Reference
이 문제에 관하여(Django REST FRAMEWORK Tutorial の 빠른 시작 프로젝트의 API 環境をdocker-compose 그리고 立ち上げる), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://dev.to/kaede_io/docker-compose-de-rest-tutorial-woyaru-22k0
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
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']
from django.contrib.auth.models import User, Group
from rest_framework import viewsets
from rest_framework import permissions
from quickstart.serializers import UserSerializer, GroupSerializer
class UserViewSet(viewsets.ModelViewSet):
"""
API endpoint that allows users to be viewed or edited.
"""
queryset = User.objects.all().order_by('-date_joined')
serializer_class = UserSerializer
permission_classes = [permissions.IsAuthenticated]
class GroupViewSet(viewsets.ModelViewSet):
"""
API endpoint that allows groups to be viewed or edited.
"""
queryset = Group.objects.all()
serializer_class = GroupSerializer
permission_classes = [permissions.IsAuthenticated]
from tutorial.quickstart.serializers
from quickstart.serializers
from django.urls import include, path
from rest_framework import routers
from 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 = [
path('', include(router.urls)),
path('api-auth/', include('rest_framework.urls', namespace='rest_framework'))
]
Reference
이 문제에 관하여(Django REST FRAMEWORK Tutorial の 빠른 시작 프로젝트의 API 環境をdocker-compose 그리고 立ち上げる), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://dev.to/kaede_io/docker-compose-de-rest-tutorial-woyaru-22k0텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)