제품 POST 시작
app.py 에서 POST 수정 중
처음이라 너무 헷갈릴 것 같아서 단계별로 설명을 붙여봄
@app.route('/product', methods=['POST'])
def saving():
# (1) img_receive로 추천하는 제품 이미지 가져오기
img_receive = request.form['product_img']
# (2) name_receive로 추천하는 제품 이름 가져오기
name_receive = request.form['product_name']
# (3) price_receive로 추천하는 제품 이름 가져오기
price_receive = request.form['product_price']
# DB에 삽입 할 자료
item={
'img' : img_receive,
'name' : name_receive,
'price' : price_receive
}
# items에 item 저장하기
db.items.insert_one(item)
#성공 여부 확인 및 메시지 출력
return jsonify({'result': 'success', 'msg':'추천 등록 완료'})
불안하게 return 부분에서 빨간 밑줄이 쭈욱 그어졌다...
오류 파티(app.py 실행 중)
1차 오류 :
IndentationError: unindent does not match any outer indentation level
=>들여쓰기 오류로 자동 줄 정렬 사용
2차 오류
SyntaxError: 'return' outside function
=> 자동 줄 맞춤 했더니 return이 밖으로 나가버림.. 탭키로 다시 들여쓰기
해결!!
오류 파티(cosmetic.html 실행 중)
1차 오류 : ~~
~~작성할 때도 아 이 부분이 이게 맞나 싶었던 부분이 결국 오류가 나는구나.
진행하려고 했던 화면
위 화면에서 추천하기 버튼을 클릭 시 입력 내용이 DB에 저장.
input 박스에 저장하려는 id->name, price 주었음.
하면서 이건 어떡하지 라고 했던 부분이
이미지 업로드 부분인데 여기서 이걸 서버에 어떻게 저장하나 어디에 id를 줘야하나 하다가 똑같이 input 박스에 id->img를 주고 서버에 저장하려 했는데
결국 오류가 남....
<div class="file_input">
<input type="text" readonly="readonly" id="img">
<label> 이미지 업로드
<input type="file" onchange="javascript:document.getElementById('file_route').value=this.value">
</label>
</div>
이미지 업로드 input 박스에 변화가 없음
그래도 한 공간이 빌 시 출력 되도록 하는 alert이 출력되는거로
아 ... 완전 망하진 않았구나 살짝 위안을 받음.
2차 오류:
(↓HTML 부분)
<div class="modal-bg">
<div class="modal">
<h2>추천하는 제품이 뭔가요?</h2>
<div class="file_input">
<input type="text" readonly="readonly" id="img">
<label>
이미지 업로드
<input type="file" onchange="javascript:document.getElementById('img').value=this.value">
</label>
</div>
<label for="name">제품명</label>
<input type="text" name="name" id="name">
<label for="price">가격</label>
<input type="text" name="price" id="price">
<button onclick="postProduct()">추천하기</button>
<span class="modal-close">X</span>
</div>
</div>
파일 input에 id를 모두 img 로 변경했지만..
정상이라면 '추천 등록 완료' 라는 메시지가 떠야하지만
아무런 반응이 없다...
console 창에 뜨는 오류
Failed to load resource: the server responded with a status of 500 (INTERNAL SERVER ERROR)
해결.
give_ 부분들을 모두 실수를 했었다.
Author And Source
이 문제에 관하여(제품 POST 시작), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@dain-choi/제품-POST-시작저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)