ft_transcendence/profiles/views.py

19 lines
673 B
Python
Raw Normal View History

from django.http import HttpRequest
from rest_framework.views import APIView
from rest_framework.response import Response
from rest_framework import permissions, status
2023-10-29 16:09:38 -04:00
from .models import ProfileModel
2023-10-24 12:28:42 -04:00
# Create your views here.
class ProfileView(APIView):
permission_classes = (permissions.AllowAny,)
def get(self, request: HttpRequest, pk: int):
2023-10-29 16:09:38 -04:00
profile: ProfileModel = ProfileModel.objects.get(pk=pk)
if (profile is None):
return Response(status=status.HTTP_404_NOT_FOUND)
2023-10-29 16:09:38 -04:00
return Response(status=status.HTTP_200_OK, data={'name': profile.user.username,
2023-10-29 16:09:38 -04:00
'title': profile.title})