노마드 코더 따라하기(get요청만)

2022. 3. 12. 18:38BackEnd/Flask (출처:시니어 개발) - 클론코딩

root 구조

main.py

from flask import Flask,render_template,request,redirect


app = Flask("SuperScrapper")

@app.route("/")
def main():
     return render_template("potato.html")

@app.route("/report")
def report():
     word =request.args.get('word')

     if word:
          word = word.lower()
     else:
         return redirect("/")
         
     return render_template("report.html",searchingBy=word)

@app.route("/<username>")
def name(username):
     return f"Hello your name is {username}"

app.run(host="0.0.0.0")

templates > potato.html

<!DOCTYPE html>
<html>
  <head>
    <title>Job Search</title>
  </head>
  <body>
    <h1>Job Search</h1>
    <form action="/report" method="get">
      <input placeholder="what jod do you want?" required name="word" />
      <button>Search</button>
    </form>
  </body>
</html>

templates > report.html

<!DOCTYPE html>

<html>
  <head>
    <title></title>
  </head>
  <body>
    <h1>Search Result</h1>
    <h3>You are looking for {{searchingBy}}</h3>
  </body>
</html>