목록DRF (34)
현제의 현재이야기

프론트와 통신 할 때, 서버가 배포되었어야 한다!! ㅠㅠ 그래서 급하게 ngrok로 임시 방편으로 해결해보려한다. Ngrok 사용하여 개발하기 웹사이트나 API 서버를 개발할 때 일반적으로는 로컬 개발환경을 구축하고 개발을 진행합니다. 하지만 때에 따라서는 외부 서비스와 연동을 하거나 외부에서 접근이 필요한 경우가 있는데 상용( velog.io 잘 된다. 단점이 내 로컬로 server가 켜져있을 때만 가능하다는 점..? 급할 때 사용하기 좋을 것 같다. [React] Django React CORS 해결하는 법 Django와 React 연동 시 CORS가 발생 하였을 경우 추가해야할 설정 문제 React 서버를 기동 후 localhost:3000으로 Django의 127.0.0.1:8000을 호출할 때 ..

구성파악의 치명적 오류 발견. 알고보니 Userplant(유저가 등록한 식물) 별로 일지가 나누어지는 형식이었다. 게다가 아까 작성된 일지를 기반으로 글 작성시 식물 이름이 그대로 넘어와야 한다. + n일차도 만들어야한다. plants/views.py #마이페이지 사이드바 - 유저에 맞는(생성한) 식물 리스트 @api_view(['GET']) @authentication_classes([SessionAuthentication,BasicAuthentication]) @permission_classes([IsAuthenticated]) def get_user_plants(request): plants = UserPlant.objects.filter(user=request.user.id).order_by('-..

코멘트 숫자 함수 작성 views.py #한 게시물 조회 @api_view(['GET']) @authentication_classes([SessionAuthentication, BasicAuthentication]) @permission_classes([IsAuthenticated]) def get_one_post(request, pk): try: post = Post.objects.get(pk=pk) comments = Comment.objects.filter(post__id = pk) post.comment_cnt = comments.count() post.save(update_fields=['comment_cnt']) serializer = GetSerializer(post) return Respo..

views.py # 댓글 조회 @api_view(['GET']) def get_comments(request, post_id): try: comments = Comment.objects.filter(post__id = post_id) for comment in comments: comment.profile_comment = comment.user.profile_image serializer = CommentGetSerializer(comments, many = True) return Response(serializer.data, status = status.HTTP_200_OK) except Post.DoesNotExist: return Response(status = status.HTTP_404_NOT..

소셜 로그인 관련 포스트 -> 서비스 고도화시 Django-Rest-Framework(DRF)로 소셜 로그인 API 구현해보기(Google, KaKao, Github) SPA(react.js), Mobile App을 DRF(Django-Rest-Framework)와 연동하여 진행하는 프로젝트의 일환으로 소셜 로그인을 구현해 보았다. medium.com 이미지 처리 관련 포스트 [AWS] S3로 이미지 업로드 AWS의 S3 활용하기 velog.io ELB + Django Rest Framework + S3 Image upload 하기 내가 겪은 수난을 여기 정리하다. 참고 S3 버킷 생성하기 Create the bucket. Create a new user: Go to AWS IAM. Click “Crea..

쿼리셋 관련 [Django] Django ORM queryset 정리(model, filter, all, get, filter, exists, create, save) Django를 하다보면 DB관련 모델링 작업이나 로직을 수행할 때 DB에 대해 직접적으로 SQL쿼리를 이용하여 DB관련 작업을 진행하는 방식이 아닌 django ORM을 통해 DB 테이블을 생성하고, C.R.U.D를 할 수 있 velog.io filter() 함수는 객체를 가져오는 것이 아니라 쿼리셋을 가져온다. 따라서 get() 함수를 사용해야 뽑아온 객체의 애트리뷰트를 이용할 수 있다. @api_view(['GET']) def recommend_test(request,pk): user = User.objects.get(pk=pk) ch..