웹개발 4주차 개발일지

yg lim·2022년 6월 12일
0

웹개발

목록 보기
4/7
  1. 4주차
    입력을 받고 처리하고 반응하는 것을 배움.
    아직 배움이 부족하므로ㅠㅠ
    복습을 많이 해야겠다...................흑;ㅅ;

  2. 쓰기=post, 보여주기=get

  • post의 영역 : 새로운 정보가 서버DB에 쌓임.

    • 1) a가 inputbox에 입력됨 : index /w F5
    • 2) 입력된 a를 A_give변수에 넣어서 보내줌 : index by ajax
    • 3) 보낸 A_give를 A_receive로 받아와서 처리함 : app by flask
    • 4) 처리한 결과 a'를 DB에 A'변수로 저장함 : app by pymongo
      ~서비스: 처리결과를 보여줌~
  • get의 영역 : DB의 정보를 꺼내줌

    • 5) A'들을 반복문으로 하나씩 분리하여 A''로 구분함 : index by ajax
    • 6) @{A''}을 적절히 넣어서 temp_html을 작성 : index by ajax
    • 7) @('#id').append(temp_html)로 body추가 :index by ajax
  1. 사전설치 및 세팅
  • 폴더
    • static
    • templates : index.html
    • venv : 만들면 자동 생성
  • app.py
    • flask : 서버운영
    • pymongo : DB쓰기
    • requests : html tag 크롤링
    • Beautifulsoup4 : 태그 파싱
  1. 서버와 클라이언트
  • 클라이언트의 주문a을
  • 서버가 A로 받고 A'로 처리(와 저장),
  • 서버는 준비된 A'와 A''를 클라이언트에게 제공.
  • 요리주문으로 이해하면 뭔가 쉬운듯 함. 글자로 된 요리주문을 받으면(ajax요청) 그 요리 레시피와 그에 필요한 재료들을 다른데서 얻어와서(크롤링) 요리를 함(파싱). 그리고 요리를 선보임(temp_html)
  1. 수수표현의 어려움
    오가는 것은 하나인데 관계된 사람이 2명이어서 주는경우, 받는경우, 되돌려주는경우, 되받는경우로 쪼개보면 새삼 복잡한 일이다. 일본어를 배울때도 수수표현이 얼마나 힘들었던가... 아무튼 이렇게 서버까지 알아보는 시간을 가졌다. 서버자체가 일종의 플랫폼인 셈이다. 클라이언트의 요청과 그에 대한 적절한 내용이 한데 모이니까. 조금은 알것같다.

from flask import Flask, render_template, jsonify, request

app = Flask(name)

from pymongo import MongoClient

client = MongoClient('localhost', 27017)
db = client.dbhomework

HTML 화면 보여주기

@app.route('/')
def homework():
return render_template('index.html')

주문하기(POST) API

@app.route('/order', methods=['POST'])
def save_order():
name_receive = request.form['name_give']
count_receive = request.form['count_give']
address_receive = request.form['address_give']
phone_receive = request.form['phone_give']

doc = {
    'name': name_receive,
    'count': count_receive,
    'address': address_receive,
    'phone': phone_receive
}
db.orders.insert_one(doc)

return jsonify({'result': 'success', 'msg': '주문 완료!'})

주문 목록보기(Read) API

@app.route('/order', methods=['GET'])
def view_orders():
orders = list(db.orders.find({}, {'_id': False}))
return jsonify({'result': 'success', 'orders': orders})

if name == 'main':
app.run('0.0.0.0', port=5000, debug=True)

profile
who want to find sth new!

0개의 댓글