본문 바로가기
TIL WIL

TIL 220502

by Youngin 2022. 5. 2.

- background-size : contain; 창을 줄여도 이미지가 안잘리고 같은 비율로 줄어들음

- 예외처리하기

  • 발음이 null일 경우 빈 텍스트를 넣어줍니다.
  • if (response["pronunciation"]==null) { $("#pronunciation").text("") } else { $("#pronunciation").text(`/${response["pronunciation"]}/`) }
  • 예문이 null일 경우 예외처리를 해줍니다.
  • let html_temp = `` if (definition["example"]!=null) { html_temp = `<div style="padding:10px"> <i>${definition["type"]}</i> <br>${definition["definition"]}<br> <span class="example">${definition["example"]}</span> </div>` } else { html_temp = `<div style="padding:10px"> <i>${definition["type"]}</i> <br>${definition["definition"]}<br> </div>` } $("#definitions").append(html_temp)

주소창에서 ?=로 문자열 입력 받기

@app.route('/detail')
def detail():  # put application's code here
    r = requests.get('<http://openapi.seoul.go.kr:8088/6d4d776b466c656533356a4b4b5872/json/RealtimeCityAir/1/99>')
    response = r.json()
    rows = response['RealtimeCityAir']['row']
    word_receive = request.args.get("word_give")
    return render_template("detail.html", rows=rows, word=word_receive)

word_receive = request.args.get("word_give") → 주소창에 detail?word_give=hi

return render_template("detail.html", rows=rows, word=word_receive)

→ html에서 word라는 변수(hi의 값을 가진) 사용가능

 

주소창에 /keyword 받기

@app.route('/detail/')
def detail(keyword):  # put application's code here
    r = requests.get('<http://openapi.seoul.go.kr:8088/6d4d776b466c656533356a4b4b5872/json/RealtimeCityAir/1/99>')
    response = r.json()
    rows = response['RealtimeCityAir']['row']
    word_receive = request.args.get("word_give")
    return render_template("detail.html", rows=rows, word=keyword)

  1. @app.route('/detail/<keyword>')
  2. def detail(keyword)
  3. return render_template("detail.html", rows=rows, word=keyword)
  4. html에서 <h3>받은 단어는 {{ word }}</h3>

이 세가지를 모두 설정해놓으면, detail/ 다음에 입력한 문자열을 활용가능

 

 

jinja2에서 딕셔너리 키값 접근 방법

  1. {{ result["word"] }}
  2. {{ result.word }}

'TIL WIL' 카테고리의 다른 글

220504 TIL  (1) 2022.05.04
TIL 220503  (1) 2022.05.04
WIL 2회차  (1) 2022.04.29
20220429 : TIL, AWS 탄력적 IP, 보안그룹, 플라스크 디버그 모드  (0) 2022.04.29
220428 TIL 플라스크 기본동작 원리이해  (0) 2022.04.28