๋ฐ˜์‘ํ˜•

๋‚ด์ผ๋ฐฐ์›€์บ ํ”„ 26

[๋‚˜๋งŒ์˜ ๋‹จ์–ด์žฅ] 12. ์ˆ™์ œ - ์˜ˆ๋ฌธ ์ €์žฅ & ์‚ญ์ œ ๊ธฐ๋Šฅ ๋งŒ๋“ค๊ธฐ

“status_give = old” ์ผ ๋•Œ๋งŒ ์˜ˆ๋ฌธ ์ž‘์„ฑ ์นธ ๋„์šฐ๊ธฐ input ๋ฐ•์Šค์— ์ž…๋ ฅ๋œ ์˜ˆ๋ฌธ์ด ํ•ด๋‹น ๋‹จ์–ด๋ฅผ ํฌํ•จํ•˜๊ณ  ์žˆ๋Š”์ง€ ํ™•์ธ ์žˆ์œผ๋ฉด DB์˜ examples ์ปฌ๋ ‰์…˜์— ์˜ˆ๋ฌธ ์ €์žฅ. ์˜ˆ๋ฌธ๋“ค ์ค‘์—์„œ ํ•ด๋‹น ๋‹จ์–ด์— ๊ด€ํ•œ ๊ฒƒ๋งŒ ์ฐพ์•„์™€์„œ ๋ณด์—ฌ์ฃผ๋Š” ํ•จ์ˆ˜๋ฅผ ๋งŒ๋“ค์–ด ํŽ˜์ด์ง€ ๋กœ๋”ฉ ์‹œ, ์ƒˆ ์˜ˆ๋ฌธ ์ €์žฅ ์‹œ, ๊ธฐ์กด ์˜ˆ๋ฌธ ์‚ญ์ œ ์‹œ ํ•จ์ˆ˜ ์‹คํ–‰. ์˜ˆ๋ฌธ ์‚ญ์ œ ์‹œ ์—ฌ๋Ÿฌ ์˜ˆ๋ฌธ ์ค‘ ์–ด๋–ค ๊ฒƒ์ธ์ง€ ๊ตฌ๋ถ„์„ ํ•˜๊ธฐ ์œ„ํ•ด ๊ฐ ์ค„์— id ๋ถ€์—ฌ ๋‹จ์–ด ์‚ญ์ œ ์‹œ ํ•ด๋‹น ์˜ˆ๋ฌธ๋“ค๋„ ๊ฐ™์ด ์ง€์›Œ์คŒ. {% if status=="old" %} // Write your own sentences! This sentence contains the word 'word'. delete I don't like using the MS Word program. delete add..

[๋‚˜๋งŒ์˜ ๋‹จ์–ด์žฅ] 11. ์™„์„ฑ๋„ ๋†’์ด๊ธฐ - ogํƒœ๊ทธ, favicon

โœ… og ํƒœ๊ทธ Open Graph ํƒœ๊ทธ๋กœ ์›นํŽ˜์ด์ง€์˜ ๋งํฌ๋ฅผ ๊ณต์œ ํ•  ๋•Œ ๋‚˜ํƒ€๋‚˜๋Š” ๋ฏธ๋ฆฌ ๋ณด๊ธฐ๋ฅผ ์„ค์ •ํ•˜๋Š” ํƒœ๊ทธ ๋ฉ”ํƒ€ ํƒœ๊ทธ์˜ ์ข…๋ฅ˜ ์ค‘ ํ•˜๋‚˜๋กœ, ‘์ œ๋ชฉ, ์„ค๋ช…, ์ด๋ฏธ์ง€, ๋งํฌ, ํƒ€์ž…’ ๋“ฑ์„ ์‚ฝ์ž…ํ•  ์ˆ˜ ์žˆ์Œ. โœ… favicon ์ฃผ์†Œ์ฐฝ์˜ ์ฆ๊ฒจ์ฐพ๊ธฐ ์•„์ด์ฝ˜ โœ… ogํƒœ๊ทธ์™€ favicon ์„ค์ •

[๋‚˜๋งŒ์˜ ๋‹จ์–ด์žฅ] 10. ๋ชฉ๋กํŽ˜์ด์ง€ - ์‚ฌ์ „์— ์—†๋Š” ๋‹จ์–ด์ผ ๋•Œ

โœ… API์—์„œ ๋‹จ์–ด ๋œป ์ฐพ์•„์„œ detail.html๋กœ ๊ฒฐ๊ณผ ๋ณด๋‚ด๋Š” ์„œ๋ฒ„ ํ•จ์ˆ˜ ๅ…ง r = requests.get(f"", headers={"Authorization": "Token [๋‚ดํ† ํฐ]"}) result = r.json() print(result) detail.html์— ๋ณด๋‚ด์ง€๋Š” result๋ผ๋Š” ๊ฐ’์„ ์‚ฌ์ „ API์—์„œ ์ฐพ์„ ์ˆ˜ ์—†์–ด์„œ ‘์ •์˜๋ฅผ ์ฐพ์„ ์ˆ˜ ์—†๋‹ค’๋Š” ๋ฉ”์‹œ์ง€ ์ฆ‰, ๋‹ค๋ฅธ ํ˜•ํƒœ์˜ ๋ฐ์ดํ„ฐ๋ฅผ ์ฃผ๊ธฐ ๋•Œ๋ฌธ์— ์ฒ˜๋ฆฌํ•˜์ง€ ๋ชปํ•ด์„œ ์—๋Ÿฌ ๋ฐœ์ƒ ! ์ด ๋•Œ ์—๋Ÿฌ๋ฅผ ๋ณด์—ฌ์ฃผ์ง€ ์•Š๊ณ  ๋‹จ์–ด ๋ชฉ๋ก ํŽ˜์ด์ง€๋กœ ๋ฆฌ๋‹ค์ด๋ ‰ํŒ… ํ•ด์•ผํ•จ โœ… ๊ฐ’์„ ์ž˜ ๋ฐ›์•„์™”์„ ๋•Œ์˜ ์ƒํƒœ์ฝ”๋“œ๊ฐ€ 200์ด๋ฏ€๋กœ 200์ด ์•„๋‹ ๋•Œ ๋ฉ”์ธํŽ˜์ด์ง€๋กœ ๋ฆฌ๋‹ค์ด๋ ‰ํŒ… ์‹œํ‚ค๊ณ  ‘๋‹จ์–ด๋ฅผ ์ฐพ์„ ์ˆ˜ ์—†๋‹ค’๋Š” ๋ฉ”์‹œ์ง€ ๋‚จ๊ฒจ์ฃผ๊ธฐ if r.status_code != 200: return red..

[๋‚˜๋งŒ์˜ ๋‹จ์–ด์žฅ] 9. ๋ชฉ๋กํŽ˜์ด์ง€ - ๊ฒ€์ƒ‰ ๊ธฐ๋Šฅ ๋งŒ๋“ค๊ธฐ

๋‹จ์–ด์žฅ์— ๋‹จ์–ด๊ฐ€ ์žˆ์œผ๋ฉด ๋‹จ์–ด์žฅ ํ•˜์ด๋ผ์ดํŠธ ์—†์œผ๋ฉด ์‚ฌ์ „์— ์žˆ๋Š” ๋‹จ์–ด์ด๋ฉด ์ƒ์„ธํŽ˜์ด์ง€๋กœ ์ด๋™ ์‚ฌ์ „์— ์—†๋Š” ๋‹จ์–ด๋ฉด ‘์—†๋Š” ๋‹จ์–ด’ ํ‘œ์‹œ โœ… ๊ฒ€์ƒ‰์„ ์œ„ํ•ด word ํ‚ค ๊ฐ’๋งŒ ๋ชจ์—ฌ์žˆ๋Š” word_list ๋งŒ๋“ค๊ธฐ let words = {{ words|tojson }}; //'์ด ๋ถ€๋ถ„์€ Html ์ฝ”๋“œ๊ฐ€ ์•„๋‹ˆ๊ณ  ์ง„์งœ ๋ฐ์ดํ„ฐ'๋ผ๊ณ  ๋งํ•ด์ฃผ๊ธฐ ์œ„ํ•ด tojson์„ ์‚ฌ์šฉ let word_list = []; //๋”•์…”๋„ˆ๋ฆฌ์—์„œ ๋‹จ์–ด๋“ค๋งŒ ๋ชจ์œผ๊ธฐ ์œ„ํ•œ list ์ƒ์„ฑ for (let i = 0; i < words.length; i++) { //words์˜ ๊ธธ์ด๋ณด๋‹ค ์งง์€ ๋™์•ˆ ๋ฐ˜๋ณต word_list.push(words[i]["word"]) //words์˜ i๋ฒˆ์งธ์˜ word ํ‚ค ๊ฐ’์„ word_list ์•ˆ์— ํ•˜๋‚˜์”ฉ ๋„ฃ์Œ } tojson ์ „ tojso..

[๋‚˜๋งŒ์˜ ๋‹จ์–ด์žฅ] 7. ์ƒ์„ธํŽ˜์ด์ง€ - ์ €์žฅ & ์‚ญ์ œ ๊ธฐ๋Šฅ ๋งŒ๋“ค๊ธฐ

1. ์ƒˆ ๋‹จ์–ด / ๊ธฐ์กด ๋‹จ์–ด ๊ตฌ๋ถ„ โœ… url ์˜ˆ์‹œ localhost:5000/detail/hello?status_give=new ⇒ ๐Ÿ’พ ๋ฒ„ํŠผ localhost:5000/detail/hello?status_give=old ⇒ ๐Ÿ—‘๏ธ๋ฒ„ํŠผ status_receive = request.args.get("status_give", "new") # status_give ๋ผ๋Š” ํŒŒ๋ผ๋ฏธํ„ฐ๋ฅผ status_receive ๋ผ๋Š” ์ด๋ฆ„์œผ๋กœ ๋ฐ›์Œ # status_give ๋ผ๋Š” ํŒŒ๋ผ๋ฏธํ„ฐ๋ฅผ ์ฃผ์ง€ ์•Š์„ ๊ฒฝ์šฐ๋ฅผ ๋Œ€๋น„ํ•ด, ๊ธฐ๋ณธ๊ฐ’์„ "new"๋กœ ์ฃผ๋„๋ก ํ•จ. return render_template("detail.html", word=keyword, result=result, status=status_receive) # detail.html์— s..

[๋‚˜๋งŒ์˜ ๋‹จ์–ด์žฅ] 6. ์ƒ์„ธํŽ˜์ด์ง€ - jinja2๋กœ ๋‹จ์–ด ๋œป ๊ฐ€์ ธ์˜ค๊ธฐ

Jinja2 ํ…œํ”Œ๋ฆฟ ์–ธ์–ด Flask ํ”„๋ ˆ์ž„์›Œํฌ์—์„œ ์‚ฌ์šฉํ•˜๋Š” ํ…œํ”Œ๋ฆฟ ์–ธ์–ด. ‘ํ…œํ”Œ๋ฆฟ’์ด ๋˜๋Š” Html ๋ฌธ์„œ์— ๋ฐ์ดํ„ฐ๊ฐ€ ๋“ค์–ด๊ฐˆ ๊ณณ์„ ํ‘œ์‹œํ•ด๋†“๋Š” ์—ญํ• ์„ ํ•ฉ๋‹ˆ๋‹ค. ํŒŒ์ด์ฐธ > setting > Template Languages > Jinja2 ์„ค์ • โœ… Owlbot API ์š”์ฒญ Flask r = requests.get(f"", headers={"Authorization": "Token [๋‚ดํ† ํฐ]"}) result = r.json() print(result) โœ… jinja2๋ฅผ ์ด์šฉํ•ด์„œ detail.html์— ๊ฐ’์„ ์ฑ„์›Œ ๋„ฃ์–ด์ฃผ๊ธฐ ์œ„ํ•ด detil.html๊ณผ ์—ฐ๊ฒฐ๋˜์–ด ์žˆ๋Š” detail ํ•จ์ˆ˜ ์•ˆ์— ์‚ฌ์ „ API์— ์š”์ฒญ์„ ๋ณด๋‚ด๊ณ  ๊ฐ’์„ ๋ฐ›์•„์˜ค๋Š” ๋ถ€๋ถ„์ด ํ•„์š”. @app.route('/detail/') def detail(keywo..

[๋‚˜๋งŒ์˜ ๋‹จ์–ด์žฅ] 5. ์ƒ์„ธํŽ˜์ด์ง€ - Ajax๋กœ ๋‹จ์–ด ๋œป ๊ฐ€์ ธ์˜ค๊ธฐ

Ajax ๊ธฐ๋ณธ ๊ณจ๊ฒฉ $.ajax({ type: "GET", //GET ๋ฐฉ์‹์œผ๋กœ ์š”์ฒญ url: "์—ฌ๊ธฐ์—URL์„์ž…๋ ฅ", //์š”์ฒญํ•  url data: {}, //์š”์ฒญํ•˜๋ฉด์„œ ํ•จ๊ป˜ ์ค„ ๋ฐ์ดํ„ฐ (GET ์š”์ฒญ ์‹œ์—” ๋น„์›Œ๋‘ ) success: function(response){ //์„ฑ๊ณตํ•˜๋ฉด, response ๊ฐ’์— ์„œ๋ฒ„์˜ ๊ฒฐ๊ณผ ๊ฐ’์„ ๋‹ด์•„์„œ ํ•จ์ˆ˜ ์‹คํ–‰ console.log(response) } }) html์—์„œ ๋‹จ์–ด ๋œป ๋ณด์—ฌ์ฃผ๊ธฐ โœ… API์—์„œ ๋‹จ์–ด ๋œป ์ฐพ์•„์„œ ๊ฒฐ๊ณผ ๋ณด๋‚ด์ฃผ๊ธฐ @app.route('/detail/') def detail(keyword): # API์—์„œ ๋‹จ์–ด ๋œป ์ฐพ์•„์„œ ๊ฒฐ๊ณผ ๋ณด๋‚ด๊ธฐ return render_template("detail.html", word=keyword) # ๋ฅผ detail.html์— word๋ผ..

[๋‚˜๋งŒ์˜ ๋‹จ์–ด์žฅ] 4. ํ”„๋กœ์ ํŠธ ์„ธํŒ…

โœ… AWS ์„œ๋ฒ„์™€ MongoDB ์—ฐ๊ฒฐ (app.py) client = MongoClient('15.164.98.36', 27017, username="test", password="test") db = client.dbsparta_plus_week2 ๋กœ์ปฌ์—์„œ ๊ฐœ๋ฐœํ•  ๋•Œ AWS ์„œ๋ฒ„์— ์žˆ๋Š” MongoDB๋ฅผ ๋ฐ”๋กœ ์—ฐ๊ฒฐํ•ด์„œ ์ฝ”๋”ฉํ•˜๋ฉด ๋‚˜์ค‘์— ๋ฐฐํฌํ•  ๋•Œ DB๋ฅผ ๋ณต์‚ฌํ•ด ์˜ฎ๊ธธ ํ•„์š”๊ฐ€ ์—†์–ด ํŽธํ•จ.

[๋‚˜๋งŒ์˜ ๋‹จ์–ด์žฅ] 3. OWLBOT API (์‚ฌ์ „ API) ์‚ฌ์šฉ

โœ… ์˜์–ด ์‚ฌ์ „ API - OWLBOT API๋ฅผ ์‚ฌ์šฉํ•ด์„œ ๋‹จ์–ด, ๋œป, ์˜ˆ๋ฌธ ๊ฐ€์ ธ์™€์•ผํ•จ. โœ… ์˜์–ด ์‚ฌ์ „ Open API Owlbot English Dictionary API Owlbot English Dictionary API owlbot.info โœ… get a token ํด๋ฆญํ•ด์„œ ์ด๋ฉ”์ผ ์ž‘์„ฑ ํ›„, ์ด๋ฉ”์ผ๋กœ API ํ‚ค ๋ฐ›๊ธฐ โœ… ํŒŒ์ด์ฌ์œผ๋กœ API์— ์š”์ฒญ ๋ณด๋‚ด๊ธฐ r = requests.get("", headers={"Authorization": "Token [ํ† ํฐ]"}) result = r.json() print(result) โœ… Ajax๋กœ ์š”์ฒญ ๋ณด๋‚ด๊ธฐ $.ajax({ type: "GET", url: "", beforeSend: function (xhr) { xhr.setRequestHeader("Authori..

[๋‚˜๋งŒ์˜ ๋‹จ์–ด์žฅ] 2. Flask๋กœ ๋ฉ€ํ‹ฐ ํŽ˜์ด์ง€ ๋งŒ๋“ค๊ธฐ

1. Flask ์„œ๋ฒ„๋ฅผ ๊ตฌ๋™์‹œ์ผœ์ฃผ๋Š” ํ”„๋ ˆ์ž„์›Œํฌ ์ฆ‰, ์„œ๋ฒ„๋ฅผ ๊ตฌ๋™ํ•  ๋•Œ ํ•„์š”ํ•œ ๋ณต์žกํ•œ ์ผ๋“ค์„ ์‰ฝ๊ฒŒ ๊ฐ€์ ธ๋‹ค ์“ธ ์ˆ˜ ์žˆ๋‹ค. 2. ํŒจํ‚ค์ง€ ์„ค์น˜ Project Interpreter ๊ฐ€์ƒํ™˜๊ฒฝ์— ํ•„์š”ํ•œ ํŒจํ‚ค์ง€ : flask, requests, pymongo 3. ๊ธฐ๋ณธ ํด๋” ๊ตฌ์„ฑ static ํด๋” : ์ด๋ฏธ์ง€, cssํŒŒ์ผ templates : html ํŒŒ์ผ app.py ํŒŒ์ผ : flask๋ฅผ ์ž‘์„ฑํ•˜๋Š” ํŒŒ์ด์ฌ ์ฝ”๋“œ 4. Flask ์‹œ์ž‘์ฝ”๋“œ (app.py) (ํ…œํ”Œ๋ฆฟ์œผ๋กœ ์™ธ์šธ ํ•„์š” X) from flask import Flask, render_template app = Flask(__name__) @app.route('/') def main(): return render_template("index.html") @app.rou..

๋ฐ˜์‘ํ˜•