in serializers.py
from .models import Profile
class ProfileSerializer(serializers.ModelSerializer):
class Meta:
model = Profile
fields = '__all__'
in views
from .serializers import ProfileSerializer
class ProfileAPI(viewsets.ViewSet):
def retrieve(self, request, pk=None):
user = get_object_or_404(User, pk=pk)
profile_serializer = ProfileSerializer(user.profile)
return Response(profile_serializer.data)
in urls.py
from .views import ProfileAPI
profile_detail = ProfileAPI.as_view({
'get': 'retrieve',
})
urlpatterns = [
...
path('<int:pk>/profile/', profile_detail, name='profile-detail'),
]
'Server > Django' 카테고리의 다른 글
[AWS CentOS] Django Nginx uWSGI 연동하기 (0) | 2019.11.15 |
---|---|
[Django] Rest Framework / ViewSet QuerySet Params (0) | 2019.11.08 |
[Django] RestFrameWork 설치 (0) | 2019.09.19 |
[Django] server start 방법 (daemon 포함) (0) | 2019.09.18 |
[Django] settings.py 기본 설정 (0) | 2019.09.18 |