주소에 입력한걸 변수처럼 쓰는 법

김엣취·2024년 6월 27일

웹개발

목록 보기
12/20
@app.route("/iloveyou/<name>/")
def iloveyou(name):
    motto = f"{name}야 난 너뿐이야!"

    context = {
        'name': name,
        'motto': motto,
    }

    return render_template('motto.html', data=context)

if __name__ == "__main__":
    app.run(debug=True)
app.route에 <name>을 적으면 됨.

그리고

motto = f"{name}야 난 너뿐이야!"

그리고 motto에 f-string으로 문자열 적기.

f-string으로 안 적으면 브라우저에 {name} 이 자체로 출력됨..

0개의 댓글