Search code examples
pythonflaskserver

Cannot find index.html when it exists (Flask Python)


In the near end of creating my server, I created a homepage and attached it to the python file, But when I tried to access the homepage from my phone, On the log it returned this:

jinja2.exceptions.TemplateNotFound: /index.html - - [25/Dec/2021 20:27:57] "GET / HTTP/1.1" 500 -

index.html exists, This is a mysterious behaviour, Advice needed.

address.py:

api = Flask(__name__)

@api.route('/')
def index():
 return render_template('/index.html')  

Solution

  • index.html should be inside a directory called templates

    Also you could do without the forward-slash in the argument to render_template:

      return render_template('index.html')