0

In some cases I want to render a template and in others I want to serve the template file. I passed the same path to render_template and send_file, but only send_file worked.

resp = render_template('templates/index.html')
resp = send_file('templates/index.html')
davidism
  • 121,510
  • 29
  • 395
  • 339
user1561108
  • 2,666
  • 9
  • 44
  • 69

1 Answers1

2

Template paths are relative to the templates root. send_file paths are relative to the app root.

render_template('file.html')
send_file('templates/file.html')

Aside, template paths aren't actually file system paths, they just happen to look like them in the default Flask case. So "templates root" really means, "lookup paths for the template loader" not "the templates folder".

davidism
  • 121,510
  • 29
  • 395
  • 339