Search code examples
pythonangularjsrestflaskflask-restful

Setting URLS for REST API using Flask


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.


Solution

  • 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