profile: rename multiple var and change to use

django rest frameword
This commit is contained in:
2023-11-12 00:03:08 +01:00
parent a7d9471d59
commit b9728dcb06
5 changed files with 22 additions and 23 deletions

View File

@ -1,21 +1,19 @@
from django.shortcuts import render
from django.views import View
from django.http import HttpResponse, HttpRequest
from django.contrib.auth.models import User
from django.http import JsonResponse
from django.http import HttpRequest
from rest_framework.views import APIView
from rest_framework.response import Response
from rest_framework import permissions, status
from .status_code import *
from .models import Profile
from .models import ProfileModel
# Create your views here.
class ProfilePage(View):
def get(self, request: HttpRequest, id: int):
class ProfileView(APIView):
permission_classes = (permissions.AllowAny,)
def get(self, request: HttpRequest, pk: int):
query: QuerySet = Profile.objects.filter(pk=id)
if (not query.exists()):
return HttpResponse(PROFILE_NOT_FOUND)
profile: ProfileModel = ProfileModel.objects.get(pk=pk)
if (profile is None):
return Response(status=status.HTTP_404_NOT_FOUND)
profile: Profile = Profile.objects.get(pk=id)
return JsonResponse({'username': profile.user.username,
return Response(status=status.HTTP_200_OK, data={'name': profile.user.username,
'title': profile.title})