오늘은 각자가 올린 파일을 하나로 합쳐보는 것과 Git&Github을 사용하는 것을 연습해봤다..
@app.route('/')
def home():
return render_template('index.html')
app.route('/')
슬래쉬 뒤에 아무 것도 없다면 이것이 메인 페이지.
그래서 여기서 선언하는 함수도 home으로 정의함.
메인페이지는 무조건 index.html
을 불러옴. 이름도 index.html
로 약속
만약, 내 페이지를 올린다면, @app.route('/m1')
같은 식으로 뒤에 붙여줌.
함수도 def m1_page():
같은 식으로 일관되게 선언.
불러오는 html의 파일명도 return render_template('m1.html')
같은 식으로 지정해주는게 좋다.
@app.route('/m3')
def m3_page():
return render_template('m3.html')
GET과 POST 코드에도 마찬가지
DB 경로 폴더도 메인 페이지 경로는 @app.route('/guestbook_team'), methods=["POST"]/["GET"])
개인 페이지 경로는 @app.route('/gestbook_m1', methods=["POST"]/["GET"]))
같은 식으로 설정.
경로 폴더가 다르니 각 POST 코드 안의 변수명은 통일해줘도 됨. 오히려 그것이 보기 편함. GET 안의 변수명은 main_comment
/ m1_comment
로 하는 것이 보기 좋음
메인 페이지 GET/POST 코드 안 함수와 각자 개인 페이지 GET/POST 코드 안 함수는 def gestbook_team_post():
/ def gestbook_m1_post():
/
def gestbook_team_get():
/
def gestbook_m1_get():
과 같은 식으로 구분 짓는 것이 좋다.
@app.route('/guestbook_m3', methods=["POST"])
def guestbook_m3_post():
nickname_receive = request.form['nickname_give']
emoticon_receive = request.form['emoticon_give']
comment_receive = request.form['comment_give']
doc = {
'nickname':nickname_receive,
'emoticon':emoticon_receive,
'comment':comment_receive
}
db.guestbook_m3.insert_one(doc)
return jsonify({'msg':'댓글 감사합니다!!!!'})
@app.route("/guestbook_m3", methods=["GET"])
def guestbook_m3_get():
m3_comments = list(db.guestbook_m3.find({},{'_id':False}))
return jsonify({'result':m3_comments})
이렇게 일관성있는 규칙으로 코드를 합칠 경우 마치 한 사람이 코딩한 것처럼 보이고 나중에 코드를 수정할 때도 해당 부분을 찾기 쉽다는 장점이 있다.
Github 공유 서버에 올리기
1. Github에 있는 파일들 가져옴.
mkdir 폴더명
cd 폴더명
git clone
git branch 브랜치명
git switch 브랜치명
git add 파일명
git commet -m "코멘트"
git push origin 내 브랜치명
github은 공유파일이라 잘못하면 날아갈까봐 손을 벌벌 떨면서 했다....