- update
- 통계학
- regexp
- 스택
- DB
- 그리디
- SQL
- N:1
- count
- Django
- drf
- distinct
- Vue
- 완전검색
- 뷰
- 쟝고
- 큐
- M:N
- Queue
- delete
- ORM
- 이진트리
- Tree
- create
- migrations
- 백트래킹
- Article & User
- 트리
- outer join
- stack
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
목록SW (84)
데이터 분석 기술 블로그

1. shell_plus 실행 및 게시글 작성 python manage.py shell_plus # 게시글 생성 Article.objects.create(title='title', content='content') 2. 댓글 생성 # Comment 클래스의 인스턴스 comment 생성 comment = Comment() # 인스턴스 변수 저장 comment.content = 'first comment' # DB에 댓글 저장 comment.save() # 에러 발생 django.db.utils.IntegrityError: NOT NULL constraint failed: articles_comment.article_id # articles_comment 테이블의 ForeignKeyField, article..

1. 댓글 모델 정의 ForeignKey() 클래스의 인스턴스 이름은 참조하는 모델 클래스 이름의 단수형으로 작성하는 것을 권장합니다. ForiegnKey 클래스를 작성하는 위치와 관계없이 외래 키는 테이블 필드 마지막에 생성됩니다. # articles/models.py class Comment(models.Model): article = models.ForeignKey(Article, on_delete=models.CASCADE) content = models.CharField(max_length=200) created_at = models.DateTimeField(auto_now_add=True) updated_at = models.DateTimeField(atuo_now=True) 2. Forign..

1. Many to one relationships - N:1 or 1:N 한 테이블의 0개 이상의 레코드가 다른 테이블의 레코드 한 개와 관련된 관계입니다. 예를 들어서 Comment - Article은 0개 이상의 댓글이 1개의 게시글에 작성될 수 있기 때문에 N:1 또는 1:N입니다. 2. 테이블 관계 3. ForiegnKey() N:1 관계 설정 모델 필드입니다.

1. Template with Authentication data 템플릿에서 인증 관련 데이터를 출력하는 방입니다. 2. 현재 로그인되어있는 유저 정보 출력하기 Hello, {{ user.username }} 3. context processors 템플릿이 렌더링 될 때 호출 가능한 콘텍스트 데이터 목록입니다. 작성된 컨텍스트 데이터는 기본적으로 템플릿에서 사용 가능한 변수로 포함됩니다. 즉, django에서 자주 사용하는 데이터 목록을 미리 템플릿에 로드해 둔 것입니다.

Logout Logout이란 Session을 Delete 하는 과정입니다. logout(request) 현재 요청에 대한 Session Data를 DB에서 삭제하고 클라이언트의 쿠키에서도 Session Id를 삭제합니다. 1. 로그아웃 로직 작성 # accounts/urls.py urlpatterns = [ path('login/', views.login, name='login'), path('logout/', views.logout, name='logout'), ] # accounts/views.py from django.contrib.auth import logout as auth_logout def logout(request): auth_logout(request) return redirect('a..

Login Login은 Session을 Create 하는 과정입니다. AuthenticationForm() 로그인 인증에 사용할 데이터를 입력 받는 built-in form입니다. 1. 로그인 페이지 작성 # accounts/urls.py app_name = 'accounts' urlpatterns = [ path('login/', views.login, name='login'), ] # accounts/views.py from django.contrib.auth.forms import AuthenticationForm def login(request): if request.method == 'POST': form = AuthenticationForm(request, request.POST) # form..

1. Django Authentication System (인증 시스템) Django Authentication System이란, 사용자 인증과 관련된 기능을 모아 놓은 시스템입니다. Authentications이란, 사용자가 자신이 누구인지 확인하는 것으로 즉, 신원 확인입니다. 1.1 사전 준비 두 번째 app accounts 생성 및 등록을 해야 합니다. auth와 관련한 경로나 키워드들을 django 내부적으로 accounts라는 이름으로 사용하고 있기 때문에 되도록 'accounts'로 지정하는 것을 권장합니다. # accounts/urls.py from django.urls import path from . import views app_name = 'accounts' urlpatterns =..

쿠키(Cookie) 서버가 사용자의 웹 브라우저에 전송하는 작은 데이터 조각입니다. 클라이언트 측에서 저장되는 작은 데이터 파일이며, 사용자 인증, 추적, 상태 유지 등에 사용되는 데이터 저장 방식입니다. 1. 쿠키 사용 원리 브라우저(클라이언트)는 쿠키를 KEY - VALUE의 데이터 형식으로 저장 이렇게 쿠키를 저장해 놓았다가, 동일한 서버에 재요청 시 저장된 쿠키를 함께 전송 쿠키는 두 요청이 동일한 브라우저에서 들어왔는지 아닌지를 판단할 때 주로 사용됩니다. 이를 이용해 사용자의 로그인 상태를 유지할 수 있습니다. 상태가 없는(stateless) HTTP 프로토콜에서 상태 정보를 기억시켜 주기 때문입니다. 2. 쿠키를 이용한 장바구니 예시 장바구니에 상품 담기 개발자 도구 - Network 탭 -..