DevOps/Django

    [Django] 장고 모델(ORM)

    장고의 모델을 만들어 준 후, 쿼리가 어떻게 작동했는지 확인 할 수 있다. 모델 작동 확인 1. 모델 생성 # /models.py class Post(models.Model): message = models.TextField() created_at = models.DateTimeField(auto_now_add=True) updated_at = models.DateTimeField(auto_now=True) auto_now_add : 최초 생성 시간을 1번 사용하여 저장, 갱신 불가능 auto_now : 장고 모델이 저장 될 때마다 현재날짜(시간)으로 갱신, 갱신 가능 2. makemigration, migrate shell python manage.py makemigrations python manag..

    [DRF] simple-jwt와 cumstom user

    [DRF] simple-jwt와 cumstom user

    공식문서를 보면서 jwt와 user를 사용해보려고 한다. 여기서 소셜인증은 사용하지 않는다. 환경세팅 1. 패키지 설치 pip install djangorestframework pip install djangorestframework-simplejwt pip install django-allauth pip install dj-rest-auth 2. settings.py # settings.py INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfil..

    [DRF] pagination custom

    [DRF] pagination custom

    DRF의 pagination을 쓸 때, 나오는 결과에 총 페이지, 현재 페이지를 추가해보려고 한다. 결과부터 보자면 커스텀을 하지 않으면 결과는 이렇게 나온다. 그리고 커스텀을 하게되면 결과는 이렇게 나온다. Setting # models.py from django.db import models class Post(models.Model): title = models.CharField('TITLE', max_length=100) content = models.TextField('CONTENT') image = models.ImageField('IMAGE', upload_to='post/%Y/%m/', blank=True, null=True) # serializers.py from rest_framewor..

    [DRF] 직렬화, 역직렬화

    직렬화와 역직렬화 DRF에서는 직렬화, 역직렬화가 따로 있는 것이 아니라, Serializer가 두 기능을 제공한다. Serializer Serializer는 Form과 Model 둘 다 비슷해 보이기도 하다. Form HTML을 다루기 위한 것. Model DB Table을 다루기 위한 것. 이 두개 모두 유효성(validation)과 직렬화(serialization) 기능을 모두 제공한다. 유효성과 직렬화를 포함하는 클래스가 Serializer 클래스 이다. Serialization 1. 메모리 내부 ( 파일, DB, Network) ↔ 외부 메모리 환경이 다르기 때문에 값 그대로 저장 할 수 없다. “홍길동” string을 내부에서 메모리 외부로 보내려면 bytes로 변환 후 보내야한다. 99 in..

    [Django] 참고사이트

    문서 https://www.django-rest-framework.org/tutorial/quickstart/ 공식문서 https://django-orm-cookbook-ko.readthedocs.io/en/latest/index.html DJANGO ORM https://www.cdrf.co/ View 정리 https://ccbv.co.uk/ cbv 정리 velog https://butter-shower.tistory.com/50DRF 개념 정리 github https://taebbong.github.io/categories/%EA%B0%9C%EB%B0%9C/Django-Rest-Framework/ tistory https://ssungkang.tistory.com/category/%EC%9B%B9%E..