Backend development with Flask: Receiving form data using Flask (+9, -3)

app.py (+8, -2)

From: curriculum/section07/lectures/09_receive_form_data_flask/start/app.py

To: curriculum/section07/lectures/09_receive_form_data_flask/end/app.py

            
            index 6af4a4c..0374211 100644
--- a/curriculum/section07/lectures/09_receive_form_data_flask/start/app.py
+++ b/curriculum/section07/lectures/09_receive_form_data_flask/end/app.py
@@ -1,9 +1,15 @@
-from flask import Flask, render_template
+import datetime
+from flask import Flask, render_template, request
 
 
 app = Flask(__name__)
 
 
-@app.route("/", methods=["GET"])
+@app.route("/", methods=["GET", "POST"])
 def home():
+    if request.method == "POST":
+        entry_content = request.form.get("content")
+        formatted_date = datetime.datetime.today().strftime("%Y-%m-%d")
+        print(entry_content, formatted_date)
+
     return render_template("home.html")
        

home.html (+1, -1)

From: curriculum/section07/lectures/09_receive_form_data_flask/start/templates/home.html

To: curriculum/section07/lectures/09_receive_form_data_flask/end/templates/home.html

            
            index 4089a35..8511364 100644
--- a/curriculum/section07/lectures/09_receive_form_data_flask/start/templates/home.html
+++ b/curriculum/section07/lectures/09_receive_form_data_flask/end/templates/home.html
@@ -23,7 +23,7 @@
   <main class="main">
     <section>
       <h1>Add new entry</h1>
-      <form class="form" action="/entry" method="POST">
+      <form class="form" method="POST">
         <p class="form__input">
           <label for="entry" class="form__label">Entry contents:</label>
           <textarea name="content" id="entry" class="form__textarea"></textarea>