1. 가상환경 세팅
2. startproject dvsnvs 생성
3. startapp snsapp 생성, settings.py에 설정
4. static 폴더 생성, settings.py에 설정
5. snsapp에 templates폴더 생성 후 html 설정
static을 불러오는 {% load static %},
6. database 초기화 python manage.py migrate
7. 게시물 모델 생성
모델 생성 후
python manage.py makemigrations
python manage.py migrate
8. admin에 등록
admin 페이지에서 모델을 확인할 수 있게 등록 후
python manage.py createsuperuser 로 admin계정 생성
9. 익명 게시판 구현하기
글쓰기 버튼 생성
사용자로부터 입력을 받아들이는 form 생성
request에 따른 동작 구현
10. 게시판 보여주기
views.py에서 post객체를 시간순으로 정렬해 가져와 index.html에 넘겨줌
template언어의 반복문을 이용해 posts 객체 표시하고 제목인 post.title에
해당 게시물을 보여주는 detail 페이지로 넘어가는 링크를 작성 (post.id를 같이 넘겨주어야함)
detail 로 넘어가는 url 설정 post_id를 같이 넘겨받아 int형 순서대로 페이지를 생성
detail 함수 생성
pk값이 post_id인 Post 객체를 post_detail에 삽입, 만약 없다면 404 error 출력
detail.html에 post_detail 객체 표시
11. 댓글 구현하기
댓글 모델 생성
ForeignKey 중요!
python manage.py makemigrations
python manage.py migrate
CommentForm 생성
detail 함수에서 CommentForm을 두 번째 인자로 detail.html에 넘겨줌
detail.html에 post_detail과 comment_form 객체 표시
new_comment 경로 추가
댓글을 저장하는 new_comment 함수 구현
finished_form을 저장하지 않고 기다렸다가 pk 값이 post_id인 post 객체를 저장하고 난 후에 save
amdin에 등록
template언어 반복문을 통해 post_detail 객체 표시
12. 로그인, 로그아웃 구현
python manage.py startapp accounts
templates 생성 후 html 작성 (static 파일 경로 설정)
settings.py에 accounts 등록
accounts app에 있는 views와 snsapp에 있는 views가 중복되므로 accounts_views로 import
login, logout 경로 설정
로그인, 로그아웃 함수 구현
로그인 하기 전이라면 user의 이름과 로그아웃 버튼을 띄우고,
그렇지 않다면 로그인 버튼을 띄움
13. 자유 게시판 구현하기
자유 게시판 model 생성
python manage.py makemigrations
python manage.py migrate
admin 등록
url 경로 등록
form 생성
함수 작성
14. 회원가입 구현
url 경로 설정
'멋쟁이 사자처럼 프로젝트' 카테고리의 다른 글
백엔드 django 실습 로그인, 로그아웃, 회원 가입 구현 (0) | 2022.05.29 |
---|---|
백엔드 Django 실습 To do project (0) | 2022.05.22 |
멋쟁이 사자처럼 홈페이지 이미지 만들기 (HTML,CSS) (0) | 2022.03.31 |