0

I created a template in the templates folder next to my Flask app. When I try to render this template, I get a 404 error in the browser. Why can't I render the template?

from flask import Flask, render_template

app = Flask(__name__, template_folder='/templates')

@app.route('/')
def index():
    return render_template('index.html')
davidism
  • 121,510
  • 29
  • 395
  • 339
Tio
  • 25
  • 1
  • 5
  • Remove the slash from `template_folder='/templates'`. It should look like `template_folder='templates'`. – xyres Mar 21 '17 at 19:59
  • Thanks for helping, all! No, its an 404 error. If you want, i can deliver screenshots as proof. I added the slash in the template_folder and the template_folder itself because of another topic i found here, when i already was searching for an answer. – Tio Mar 21 '17 at 20:36
  • Okay. Why can't flask find the template, even without the template_folder part or part edited as `template_folder='templates'`? – Tio Mar 21 '17 at 20:52

1 Answers1

3

You don't need to specify a template folder for the app, it's automatically set to 'templates'. As that default shows, it's a relative path.

You've provided an absolute path though, /templates is "the templates folder at the root of the filesystem". Your machine is unlikely to have a templates folder with your templates at the root.

Remove the template_folder parameter, or remove the leading /.

davidism
  • 121,510
  • 29
  • 395
  • 339