I am making a Flask website, but the replace() method isn't working

It says TypeError: replace() argument 2 must be str, not datetime.date

to fix this, just add today = str(today) after today = datetime.date.today()

It still won’t work though because even though you are replacing {today} with the current date, you actually aren’t making that change to page.

You need to change page.replace("{today}", today) to
page = page.replace("{today}", today)

def portfolio():
  today = datetime.date.today()
  today = str(today) #here
  page = ""
  f = open("templates/Portfolio.html", "r")
  page = f.read()
  page = page.replace("{today}", today) #here 
  f.close()
  return page
2 Likes