Backend development with Flask: Formatting dates correctly in our entries (+13, -2)

app.py (+12, -1)

From: curriculum/section07/lectures/11_formatting_dates_correctly_microblog/start/app.py

To: curriculum/section07/lectures/11_formatting_dates_correctly_microblog/end/app.py

            
            index 9dbdcc6..6ad685f 100644
--- a/curriculum/section07/lectures/11_formatting_dates_correctly_microblog/start/app.py
+++ b/curriculum/section07/lectures/11_formatting_dates_correctly_microblog/end/app.py
@@ -1,5 +1,8 @@
 import datetime
 from flask import Flask, render_template, request
+from dotenv import load_dotenv
+
+load_dotenv()
 
 
 app = Flask(__name__)
@@ -14,4 +17,12 @@ def home():
         formatted_date = datetime.datetime.today().strftime("%Y-%m-%d")
         entries.append((entry_content, formatted_date))
 
-    return render_template("home.html", entries=entries)
+    entries_with_date = [
+        (
+            entry[0],
+            entry[1],
+            datetime.datetime.strptime(entry[1], "%Y-%m-%d").strftime("%b %d"),
+        )
+        for entry in entries
+    ]
+    return render_template("home.html", entries=entries_with_date)
        

home.html (+1, -1)

From: curriculum/section07/lectures/11_formatting_dates_correctly_microblog/start/templates/home.html

To: curriculum/section07/lectures/11_formatting_dates_correctly_microblog/end/templates/home.html

            
            index 73ae245..897d86e 100644
--- a/curriculum/section07/lectures/11_formatting_dates_correctly_microblog/start/templates/home.html
+++ b/curriculum/section07/lectures/11_formatting_dates_correctly_microblog/end/templates/home.html
@@ -37,7 +37,7 @@
         <article class="entry">
           <div>
             <h2 class="entry__title">{{ entry[0] | truncate(30, true) }}</h2>
-            <time class="entry__date" datetime="{{ entry[1] }}">• {{ entry[1] }}</time>
+            <time class="entry__date" datetime="{{ entry[1] }}">• {{ entry[2] }}</time>
           </div>
           <p class="entry__content">
             {{ entry[0] }}