분류 전체보기

    [Django] F

    F란? Django에서 제공하는 F 객체는 데이터베이스 필드의 값을 참조하고 조작하는 데 사용되는 객체이다. F 객체를 사용하면 데이터베이스 쿼리를 통해 필드 값을 직접 업데이트 할 수 있다. F 객체를 사용하면 데이터베이스에 직접 쿼리를 보내지 않고도 필드 값을 업데이트할 수 있으므로, 데이터의 일관성을 유지하면서 성능을 향상시킬 수 있다. 예시 from django.db.models import F class CartListCreateAPIView(ListCreateAPIView): """ 장바구니 생성 및 리스트 """ queryset = Cart.objects.all() serializer_class = CartSerializer def get_queryset(self): user = self.r..

    [Error]'utf-8' codec can't decode byte 0xff in position 0: invalid start byte

    [Error]'utf-8' codec can't decode byte 0xff in position 0: invalid start byte

    문제발생 class ProductSerializer(serializers.ModelSerializer): brand_id = serializers.PrimaryKeyRelatedField( queryset=Brand.objects.all(), write_only=True ) brand = serializers.SerializerMethodField(read_only=True) class Meta: model = Product fields = [... 'brand'] def get_brand(self, obj): """ 브랜드 정보 """ brand = obj.brand_id print('brand_logo_img : ', brand.logo_img) if brand: brand_data = { 'id':..

    [ERROR] most likely due to a circular import

    문제발생 제목에 있는 에러는 순환참조 에러로, 두 개 이상의 모듈이 서로를 참조하고 있는 상태이다. 이 에러가 발생하게 된 이유는 서로 다른 app의 models.py에서 import를 참조했기 때문이다. # user/models.py from product.models import Brand class Coupon(models.Model): ... class CouponUser(models.Model): ... # product/models.py from coupons.models import CouponUser class AlProduct(models.Model): ... class AlProductImage(models.Model): ... class AlProductOption(models.Mod..

    [Oracle Cloud] 인스턴스 생성

    [Oracle Cloud] 인스턴스 생성

    1. 오라클 클라우드 Instance 생성 1. 메인에서 Instance 2. Create instance 클릭 3. OS Image 변경 4. Networing 변경 4. SSH 키 추가 키추가 하는 방법은 많지만, private key와 public key를 다운로드 받는 자동으로 키 쌍 생성을 선택해서 해주면 된다. 2. 보안 그룹과 서브넷, 방화벽 설정 1. 인스턴스 세부정보 > VNIC에서 보안 정책 설정 변경 2. 보안 목록으로 이동 3. 수신 규칙 추가. HTTP 80, HTTPS 443, 개발 중인 프로젝트 8000을 입력해준다. 포트를 여러개 입력할 때는 공백없이 입력해야한다. 3. VM Instance에서 방화벽 설정 $ sudo iptables -I INPUT 5 -i ens3 -p ..

    [Django] django-pydenticon - 디폴트 프로필

    https://django-pydenticon.readthedocs.io/en/0.2/installation.html Installation — Django Pydenticon 0.2 documentation Configuring your Django installation Once Django Pydenticon has been installed, you need to perform the following steps in order to make it available inside of your Django project: Edit your project’s settings configuration file (settings.py), and update django-pydenticon.readthed..

    [DRF] 이미지 URL 호스트, 포트 제거

    [DRF] 이미지 URL 호스트, 포트 제거

    Generics View를 이용할 때 image url에 호스트명이 추가되어 나타났다. /media/board/~~로 시작하게 하기위해서 아래와 같이 serializer를 변경하면 된다. 1. 변경전 # serializers.py class PostSerializer(serializers.ModelSerializer): class Meta: model = Post fields = '__all__' 2. 변경후 # serializers.py class PostSerializer(serializers.ModelSerializer): image = serializers.SerializerMethodField() class Meta: model = Post fields ='__all__' def get_imag..

    [DRF] Swagger 사용하기

    https://drf-yasg.readthedocs.io/en/stable/readme.html drf-yasg - Yet another Swagger generator — drf-yasg 1.20.1 documentation Since the schema does not usually change during the lifetime of the django process, there is out of the box support for caching the schema view in-memory, with some sane defaults: caching is enabled by the cache_page decorator, using the default Django cac drf-yasg.readt..

    [Docker] 기본 명령어

    버전 확인 docker -v docker --version 이미지 이미지 조회 docker images [옵션] [REPOSITORY[:TAG]] 옵션 (단축) 옵션 (풀) 예시 -a --all -f --filter docker images --filter=reference="test*" || docker images test* 이미지 빌드 docker build . 옵션 (단축) 옵션 (풀) 예시 -t --tag docker build -t test_docker . 이미지 태그 docker tag 기존_IMAGE명[:TAG] 변경_IMAGE명[:TAG] 기존_IMAGE는 삭제되지 않고, 변경_IMAGE명 이미지가 새로 생성된다. 이미지 다운로드 docker pull [옵션] 이미지명[:태그] 옵션 (단..

    [Django] 프로젝트 세팅 ( + React )

    1. initial setting 1-1. 가상환경 python -m venv venv를 이용하여 가상환경으로 만들기. 1-2. git init 적용 git init을 이용하여 git 활성화 .gitignore 생성하여 밑에 있는 url 복사. https://www.toptal.com/developers/gitignore/api/django 1-3. backend - django 설치. pip install django 명령어를 이용한 django 설치. python -m django startproject python manage.py migrate python manage.py createsuperuser settigs.py 설정 # react에서 관리하는 파일 제외하고 css파일 등을 관리. STA..

    [Django] SENDGRID를 이용한 메일 보내기.

    [Django] SENDGRID를 이용한 메일 보내기.

    1. API키 생성 https://app.sendgrid.com/settings/api_keys SendGrid app.sendgrid.com 위 사이트로 들어가서 API키를 생성한다. 2. 발신자 인증 https://app.sendgrid.com/settings/sender_auth SendGrid app.sendgrid.com Sender Authentication(발신자 인증)에 들어가서 Verify a Single Sender(단일 발신자 확인)을 인증한다. 3. Django 프로젝트에 적용하기. 3-1. 환경변수 설정 및 확인 powershell에서 환경변수로 SENDGRID_API_KEY를 등록하기 위해 $Env:SENDGRID_API_KEY = "~~~"를 해준다. 장고 shell에 들어가 ..