전체 글 147

Django Seed(Response와 Serializer)

0. 기초작업api_pjt 라는 이름의 프로젝트를 생성articles 앱을 생성하고 기본적인 url 구조를 만듦/api/v1/articles/로 들어오면 articles 앱의 urls로 연결articles 앱의 models.py를 작성Artcile 모델 클래스를 작성하고 아래 필드를 포함titlecontentcreated_atupdated_at조회를 하려면 데이터가 필요Django Seed :→ 매번 create하는 것도 너무 힘들기에 자동으로 많이 생성해주는 라이브러리 installpip install django-seed→ freeze !settings.pyINSTALLED_APPS = [ "django.contrib.admin", "django.contrib.auth", "djang..

Django 2024.08.29

파이썬 함수(is, ==의 차이/ 바다코끼리/ suppress[try catch] / big num)

1. str# add_string_by_plus 주소가 계속 바뀜add_string_by_plus = ""for i in range(50): add_string_by_plus += str(i)print(add_string_by_plus)---------------------------------#좀더 최적화된 방식import ioadd_string_by_plus = io.StringIO()for i in range(50): add_string_by_plus.write(str(i))string_by_plus = add_string_by_plus.getvalue()print(string_by_plus)  2. try catch와 contextlib.suppress filename = "타겟.jpg..

파이썬 2024.08.29

장고 TemplateSyntaxError

아래와 같은 오류가 뜬다면 두가지를 체크해보자TemplateSyntaxError at /instagram/new/ Invalid block tag on line 34: 'endblock', expected 'elif', 'else' or 'endif'. Did you forget to register or load this tag?  1. static 파일을 불러오는 html 각 상단에 {%load static%}이 있는지 확인.(base.html에 있어 상속 받는다 해도 각 html에 또 추가해야함.) 2. 코드 내용 중, 주석 처리를 이런식으로 한 내용 중 안에 if문이 있으면 주석 삭제.는 장고 문법이 아니어서 안의 내용을 인식할 수 있음. comment태그 사용 권장.

Django 2024.08.28

git 협업시 메뉴얼

- 새 클론을 받거나, 폴더를 다 지우고 다시 클론을 받을 경우 처음 구축환경1. clone2. python -m venv venv3. source venv/Scripts/activate4. pip install -r requirements.txt- 코드 개발 하기 전 사전 세팅git switch main(혹은 머지하는 곳)git pullgit switch (자기 브랜치)git merge maingit push코드 작업하기 전 자기 브랜치인지 꼭 확인하기!!!- 개발해서 Pull request하는 경우깃헙 사이트 가서 pull request 생성충돌 안나면 그대로 만들고충돌 난다고 하면,1. 코드로 돌아와서 git switch main(혹은 머지하는 곳)2. git pull3. git switch (자기..

잡다한 것 2024.08.27

Anaconda 가상환경 설정

0. 매 프로젝트마다 venv설치하는 것이 프로그램이 무거워져서 Anaconda를 이용 1. 아나콘다 설치 후, 아나콘다 네비게이터 실행2. Enviroments 탭에서 가상환경을 대체하는 환경을 Create함.3. 만든 환경 선택4. [Ctrl] + [Shift] + [P]을 눌러 자신이 사용할 anaconda 환경에 설치된 python.exe 선택    5. 자신의 프로젝트로 가서 가상환경을 anaconda로 바꿈 위와같이 하면 venv없이 사용가능. (마찬가지로 anaconda환경에 pip install -r requirements.txt 등 인스톨은 해야함)

Anaconda 2024.08.26

백엔드와 Django DRF, RESTful API

01. RESTful API02. JSON ✅ 기존의 DjangoDjango는 Web App을 빠르게 개발하기 위한 고수준의 웹 프레임워크즉, 기존에는 Web의 전체 기능이 모두 들어있는 Web Application을 제작→ 요청에 대해서 html 파일(웹 페이지)을 응답하는 Web Application을 만듦MTV를 활용한 Web데이터 모델링, URL 라우팅, 템플릿 시스템, 관리자 기능, 세션, 보안 …✅ 백엔드로써의 Django보여지는 부분은 처리하지 않고 오직 로직에 집중하는 형태를 만듦→ 요청에 대해 처리한 결과 데이터를 응답하는 형태Django REST Framework (DRF)를 이용함→ Django + DRF라고 하는 패키지를 살짝 얹은것(확장)으로 Django를 다룰 수 있다면 무리없이..

Django 2024.08.23

Django Bootstrap, Fontawesome

01. Bootstrap02. Fontawesome   01. Bootstrap: https://getbootstrap.com  BootstrapPowerful, extensible, and feature-packed frontend toolkit. Build and customize with Sass, utilize prebuilt grid system and components, and bring projects to life with powerful JavaScript plugins.getbootstrap.combase.html의 head에 위 사진 속 CSS 링크를 첨부base.html의 body 마지막줄에 JS 링크를 첨부사이트 속 사용법을 참고하여 원하는 것을 코드에 적용02. Fontawes..

Django 2024.08.22

Model Relationship(M:N)

01. ManyToMany Relationship(M:N) ManyToMany: https://docs.djangoproject.com/en/4.2/ref/models/fields/#manytomanyfield Model field reference | Django documentationThe web framework for perfectionists with deadlines.docs.djangoproject.com 다대다(M:N) 관계 설정시 사용하는 모델 필드입니다.예시) 좋아요→ 하나의 게시글도 여러명의 유저에게 좋아요를 받을 수 있음→ 한 명의 유저는 여러개의 게시글을 좋아할 수 있어요! 중계 테이블을 이용해서 관계를 표현(걍 테이블 하나 더 만듦) models.ManyToManyField()..

Django 2024.08.21

Custom UserModel(플젝 시작시 유의)

01. Custom User Model02. 1:N 관계 확장하기    01. Custom User Model 현재 UserModelDjango의 기본 User Model을 사용대부분의 프로젝트에서는 User Model에 더 많은 기능들이 필요Django는 AUTH_USER_MODEL setting을 변경하여 기본 User Model을 대체할 수 있음만약 기본 User Model을 사용하더라도 Custom User Model을 사용하는 것을 권장따라서!AUTH_USER_MODEL 설정은 반드시 프로젝트 최초 마이그레이션에서 함께 진행하기를 권장USER Model은 비지니스로직 깊숙이 관여되기에 중간에 변경하면 많은 변경사항을 야기# accounts/models.pyfrom django.db import..

Django 2024.08.20

Model Relationship (1:N)

굉장히 흔히 사용되는 관계1:N 관계 예시만약 Article에 Author라는 개념을 둔다면,하나의 Article은 한 명의 Author를 가질 수 있음한 명의 Author는 여러개의 Article을 가질 수 있음만약 Article에 Comment라는 개념을 둔다면,하나의 Article은 여러개의 Comment를 가질 수 있음하나의 Comment는 하나의 Article을 가질 수 있음댓글(Comment) 구현articles/models.pymodels.ForeignKey(, on_delete=)#articles/models.pyclass Comment(models.Model): article = models.ForeignKey(Article, on_delete=models.CASCADE) co..

Django 2024.08.19