스파르타 코딩 클럽 4주차 후기

Agbi·2021년 8월 28일
0
post-thumbnail

배운 내용 :

  • Flask

    • 폴더 설정

      • static 폴더 (이미지, css 파일)
      • templates 폴더 (htrml 파일)
      • app.py 파일
    • app.py

      from flask import Flask, render template
      app = Flask(__name__)
      
      @app.route('/')
      def home():
         return render_template('index.html')
      
      if __name__ == '__main__':
         app.run('0.0.0.0',port=5000,debug=True)
    • GET

      • 통상적 데이터 조회에 활용
      • 데이터 전달: URL 뒤에 물음표를 붙여 key=value로 전달

      GET 요청 API

      @app.route('/test', methods=['GET'])
      def test_get():
         title_receive = request.args.get('title_give')
         print(title_receive)
         return jsonify({'result':'success', 'msg': '이 요청은 GET!'})

      GET 요청 확인 Ajax

      $.ajax({
         type: "GET",
         url: "/test?title_give=봄날은간다",
         data: {},
         success: function(response){
             console.log(response)
         }
      }
  • POST

    • 통상적 데이터 생성, 변경, 삭제에 활용
    • 데이터 전달: 바로 보이지 않는 HTML body에 key:value 형태로 전달

    POST 요청 API

    @app.route('/test', methods=['POST'])
    def test_post():
       title_receive = request.form['title_give']
       print(title_receive)
       return jsonify({'result':'success', 'msg': '이 요청은 POST!'})

    POST 요청 확인 Ajax

    $.ajax({
       type: "POST",
       url: "/test",
       data: { title_give:'봄날은간다' },
       success: function(response){
           console.log(response)
       }
    }
  • meta 태그

    • head에 포함된, 눈으로 보이는 body 외 속성을 설명해 주는 태그들
    • "og:"

예제 결과 :

  • 책리뷰 사이트 (제목, 저자, 코멘트 제출 시 mongodb에 저장하여 테이블에 행 추가)

  • 영화 메모장 (영화 url, 코멘트 제출 시 mongodb에 저장하여 메타정보 포함 카드 추가)

숙제 결과 :

  • 원페이지 쇼핑몰 주문 정보 제출 시 mongodb에 저장하여 테이블에 행 추가

소감 :

  • 4주차는 이론수업보다 예제 위주로 달렸음
  • 확실히 여러번 반복하니 손에 익게 됨
  • 실제로 많이 해보고 모르는 건 검색해보며 부딪히는 게 제일 도움될 것 같긴 함
  • 굿!
profile
코린이

0개의 댓글

관련 채용 정보