0

I have two files - app.py which contains the code for a REST API and another page index.html which displays some contents of the API using AngularJS. Currently, I have to open the index.html file from the browser to get it working (after the server http://localhost:5000 is deployed).

I tried

@app.route('/')
def index():
return render_template('/index.html',
                       title='Home')

It is giving the error "TemplateNotFound: /index.html". Currently, app.py and index.html are in the same directory. How do I change the format to let Flask know that it has to render the page index.html on this URL.

punjabidon
  • 11
  • 3

2 Answers2

2

In flask, templates should be located in a directory called templates

Your app should look like :

./app.py
./templates/index.html

http://flask.pocoo.org/docs/0.10/tutorial/templates/ : Put the following templates into the templates folder

sknat
  • 468
  • 3
  • 14
  • That seems to solve this error. However, it is still unable to render it because index.html contains an AngularJS script for outputting the REST API contents. The error is that 'x is undefined' (I have used x to loop through a controller object which sends a GET request to the page, and thus outputs {{x.name}} and so on). – punjabidon Mar 09 '16 at 10:32
0

Try removing the slash from the template path. It is not necessary when the files are in the same directory.

return render_template('index.html',
                   title='Home')
Kelly Keller-Heikkila
  • 2,544
  • 6
  • 23
  • 35