์ƒˆ์†Œ์‹

๐Ÿ ํŒŒ์ด์ฌ (Python)

Flask - ๊ฐ„๋‹จ ์˜ˆ์ œ : ๋™์  URI ์‚ฌ์šฉํ•˜๊ธฐ get user profile

  • -

 

uri์˜ ๋์— ์ถ”๊ฐ€๋œ username์ด ๋™์ ์œผ๋กœ ๋ณ€๊ฒฝ๋˜๋Š” ๋ถ€๋ถ„์ด๋‹ค.

<๋ณ€ํ™˜ํƒ€์ž… : ๋ณ€์ˆ˜๋ช… > ํ˜•ํƒœ๋กœ ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•˜๋ฉฐ, string์ด ์•„๋‹Œ intํ˜•์ด๋‚˜, ๊ธฐํƒ€ ๋‹ค๋ฅธํ˜•ํƒœ๋กœ๋„ ๋ณ€ํ™˜ํ•˜์—ฌ ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•˜๋‹ค.

 

 

 

app.py
from flask import Flask , render_template

app = Flask(__name__)

@app.route("/profile/<username>")
def profil(username):
    return render_template(username)


if __name__ == "__main__":
    app.run(host = "127.0.0.1", port=5000, debug = True)

 

 

 

 

home.html
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>profile</title>


</head>
<body>
    <h1>user profile search</h1>
    <form method = "POST">
    <input type="text" name = 'username'>
    <button type="submit" method="POST"  >๊ฒ€์ƒ‰</button>
</form>
</body>
</html>

 

*์ถ”๊ฐ€์ ์œผ๋กœ
๋™์ ์œผ๋กœ uri๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•์ค‘์—๋Š”
url_for() ํ•จ์ˆ˜๋ฅผ ์ด์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•๋„ ์žˆ๋‹ค๊ณ  ํ•œ๋‹ค. (๋‚˜์ค‘์— ํ•œ๋ฒˆ ์ฐพ์•„๋ณด์ž)

 

Contents

ํฌ์ŠคํŒ… ์ฃผ์†Œ๋ฅผ ๋ณต์‚ฌํ–ˆ์Šต๋‹ˆ๋‹ค

์ด ๊ธ€์ด ๋„์›€์ด ๋˜์—ˆ๋‹ค๋ฉด ๊ณต๊ฐ ๋ถ€ํƒ๋“œ๋ฆฝ๋‹ˆ๋‹ค.