Why won't this function work?

from flask import Flask, redirect
import datetime

app = Flask(__name__)
@app.route('/')
def fiftySix():
  date = datetime.date.today()
  blogtitle = "AGI will kill us all. Heres how."
  title = "Blog 1"
  text = "It will because of many reasons. The end"
  image = "picard.jpg"
  link = "https://replit.com/@DavidAtReplit/Day-056-Solution#main.py"
  
  page = ""
  f = open("template/blog.html", "r")
  page = f.read()
  f.close()
  page = page.replace("{blogtitle}", blogtitle)
  page = page.replace("{title}", title)
  page = page.replace("{text}", text)
  page = page.replace("{image}", image)
  page = page.replace("{link}", link)
  page = page.replace("{date}", f"{date}")
  return page
@app.route('/blog2')
def blog2():
  return
redirect("https://replit.com/@DavidAtReplit/Day-077-Solution#main.py")
app.run(host = "0.0.0.0", port = 81)

Apparently the blog2 function isn’t working but I’ve included a return statement before the redirect which should be fine?

1 Like

It is because of the return before the redirect
Adding that there means that the redirect function never gets called
You could do this:

@app.route('/blog2')
def blog2():
  return redirect("https://replit.com/@DavidAtReplit/Day-077-Solution#main.py")

PS: Use code blocks for better formatting and readability (surround your code with triple backticks - ```)

1 Like