ft_transcendence/profiles/views.py

21 lines
693 B
Python
Raw Normal View History

2023-10-24 12:28:42 -04:00
from django.shortcuts import render
2023-10-29 16:09:38 -04:00
from django.views import View
from django.http import HttpResponse, HttpRequest
from django.contrib.auth.models import User
from django.http import JsonResponse
from .status_code import *
from .models import Profile
2023-10-24 12:28:42 -04:00
# Create your views here.
2023-10-29 16:09:38 -04:00
class ProfilePage(View):
def get(self, request: HttpRequest, id: int):
query: QuerySet = Profile.objects.filter(pk=id)
if (not query.exists()):
return HttpResponse(PROFILE_NOT_FOUND)
profile: Profile = Profile.objects.get(pk=id)
return JsonResponse({'username': profile.user.username,
'title': profile.title})