Python Study
-
CH1. 특별메서드Python Study 2020. 7. 21. 14:08
200721 제목 1 1. 특별 메서드 (예시) __len()__ : 길이를 return __getitem()__ : obj[key] 형태의 호출을 지원 hello Class FrenchDeck: def __getitem__(self, position): return self._cards[position] 위에서 처럼 __getitem__의 return이 List로 재정의 된 경우, Object를 상속받았음에도 불구하고 instance는 표준 파이썬 List처럼 행동한다. 따라서 reversed(), choice(), sorted() 등을 사용할 수 있게 된다. 아래 4가지 예시를 보자 deck = FrenchDeck() # EX 1 : Random Choice from random import choi..
-
9. Django 기초 (7) : MVCPython Study 2020. 3. 5. 19:45
Board를 만들어보자. - Model을 건드렸을 때는 Migration을 반드시 해주자. (새로 모델을 만들었다면, setting.py - INSTALLED_APPS에 모델을 추가해주자) template/board_list.html에서 {{ boards }}로 확인 >>> Migartion 문제 생겼을 때 참고 링크 : https://simpleisbetterthancomplex.com/tutorial/2016/07/26/how-to-reset-migrations.html Migartion 파일 삭제 find . -path "*/migrations/*.py" -not -name "__init__.py" -delete find . -path "*/migrations/*.pyc" -delete 이래도 해결..
-
6. Django 기초 (4) : Session, RedirectPython Study 2020. 3. 3. 23:22
로그인 시에는 Session 생성은 password check로 끝난다. * redirect, render 시에는 반드시 import를 해주자 from django.shortcuts import render, redirect - home 에서 user session을 불러오는 방법. - Model.objects.get(pk=id)를 통해 User 정보를 Model로부터 가져온다. - Session 정보는 개발자도구 - Application - Cookies에서 볼 수 있다. - request.session['user'] = fcuser.id 당시에 sessionid가 생성된다. 이는 브라우저마다 다르게 생성된다. - 서버 입장에서 sessionid가 다르면, 다른 것으로 취급된다. - loggout - ..
-
5. Django 기초 (3) : from CDN to STATICPython Study 2020. 3. 3. 22:32
- CDN : Contents Delivary Network (설명 링크 : https://docs.microsoft.com/ko-kr/azure/cdn/cdn-overview) - CDN을 STATIC으로 바꿔보자! Project - STATIC 폴더를 만든다. setting.py에서 아래와 같이 설정 아래 Bootstrap 사이트에서 테마를 XXX.min.css 파일을 받아 STATIC 폴더에 넣는다. Bootswatch: Free themes for Bootstrap Customizable Changes are contained in just two SASS files, enabling further customization and ensuring forward compatibility. boots..
-
4. Django 기초 (2) : VIEW, 로그인 만들기Python Study 2020. 3. 3. 22:21
1. VIEW - 로그인 페이지 만들기 - template 폴더 안에 register.html 파일을 만든다. - bootstrap에서 css, js link를 연결해준다. - bootstrap forms에서 login form을 붙인다. 회원가입 Email address We'll never share your email with anyone else. Password Check me out Submit views.py 에 request 함수를 추가한다. Project / urls.py에 path 추가한다. Models / urls.py 파일을 만들어 아래와 같이 작성한다. 2. form parsing - N/M 회원가입 {{ error }} {% csrf_token %} 사용자 이름 Password ..
-
3. Django 기초 (1) : Project Build, Model, DB, AdminPython Study 2020. 3. 3. 19:19
1. Project-Build on terminal django-admin startproject [PROJECT-NAME] cd [PROJECT-NAME] django-admin startapp board MVC model을 위해 app 폴더 내에 [templates] 폴더를 만들면 장고가 알아서 읽는다. app 생성 후에는 등록을 해야하는데, PROEJCT 폴더 - PROEJCT 폴더 - settings.py에서 아래와 같이 등록을 해준다. 2. Model - DB 설정 위와 같이 django.db pakage에서 models를 import한다. Class 내에서 username, password, register_dttm을 Django form으로 받는다. Meta Class는 DB table의 이..