๐Ÿช ํ”Œ๋ผ์Šคํฌ์— ๋‹ด๊ธด ์ฟ ํ‚ค ๐Ÿพ

2308 ๋‹จ์–ด pythonwebdevflaskbeginners

์ฟ ํ‚ค๋ž€ ๋ฌด์—‡์ž…๋‹ˆ๊นŒ?



์ฟ ํ‚ค๋Š” ์ผ์ข…์˜ ์ €์žฅ์†Œ์ด์ง€๋งŒ ๋งค์šฐ ์ž‘์€ ์ €์žฅ์†Œ์ž…๋‹ˆ๋‹ค. ์ฃผ๋กœ csrf_token, ๋กœ๊ทธ์ธ ์ž๊ฒฉ ์ฆ๋ช…( ์•”ํ˜ธํ™”๋จ), ๊ธฐ๋ณธ ์„ค์ •, ์‚ฌ์ดํŠธ ํ†ต๊ณ„ ๋ฐ/๋˜๋Š” ์‚ฌ์šฉ์ž ํ™œ๋™๊ณผ ๊ฐ™์€ ์ž‘์€ ์ •๋ณด๋ฅผ ์ €์žฅํ•˜๋Š” ๋ฐ ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค. ์ฟ ํ‚ค๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ์›น์‚ฌ์ดํŠธ๋ฅผ ๋ณด๋‹ค ๊ฐœ์ธํ™”ํ•˜์—ฌ ์›น์‚ฌ์ดํŠธ ์‚ฌ์šฉ์ž์—๊ฒŒ ๋ชฐ์ž…ํ˜• ๊ฒฝํ—˜์„ ์ œ๊ณตํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

Flask์—์„œ "์ฟ ํ‚ค"๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•์€ ๋ฌด์—‡์ž…๋‹ˆ๊นŒ?



ํ”Œ๋ผ์Šคํฌ์—์„œ ์ฟ ํ‚ค๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์€ ๋งค์šฐ ๊ฐ„๋‹จํ•ฉ๋‹ˆ๋‹ค. ํ”Œ๋ผ์Šคํฌ์—์„œ ์ฟ ํ‚ค๋Š” ๋ถˆ๋ณ€ ์‚ฌ์ „์ด๋ฉฐ ์‚ฌ์ „์œผ๋กœ ํ˜ธ์ถœํ•  ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค. request.cookies ์†์„ฑ์˜ ๊ฐ’์„ ๋ณด๋ ค๋ฉด ์‚ฌ์ „ ๊ฐœ์ฒด๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด ์ดํ•ดํ•ด๋ณด์ž.

์•ฑ.ํŒŒ์ด

from flask import Flask, request, make_response, redirect, url_for, render_template

app = Flask(__name__)

@app.route("/")
def home():
    userName = request.cookies.get("name")
    if userName:
        return f"Hello {userName}." 
    else:
        return redirect(url_for("setName"))


์—ฌ๊ธฐ์—์„œ ๊ณ„์† ์ฝ์œผ์‹ญ์‹œ์˜ค๐Ÿช Cookies in Flask ๐Ÿพ.

์ข‹์€ ์›นํŽ˜์ด์ง€ ์ฆ๊ฒจ์ฐพ๊ธฐ