-1

I want to implement a machine learning model but i implement flask,i am getting this error template not found even though i have template folder. I have tried all the possible solution given on stack overflow but nothings works,please help me. The basic code is to run the index page and even that is not working.

from flask import Flask,render_template
app = Flask(__name__, template_folder="C:/Users/sweet/Music/Rumor_Detection_Project_Copy/Front_End/templates")
app.debug=False
@app.route('/')

def index():
    with app.app_context(), app.test_request_context():
        template = render_template('C:/Users/sweet/Music/Rumor_Detection_Project_Copy/Front_End/templates/index.html')



if __name__ == "__main__":
    app.run()

Thing which I have tried are:

  • Renaming templates to template
  • Using the proper sub-directory
  • Debug feature both on and off
  • Catch statement for error 500

PLEASE HELP AS THIS IS THE BASIC AND I HAVE TO DO A LOT OF OTHER THINGS TOO

code with error description

Karthik
  • 2,181
  • 4
  • 10
  • 28
Alisha
  • 1
  • Can you try `index.html` instead of the full path? `render_template` normally takes the name of the template inside the template folder. – FoolsWisdom Aug 14 '20 at 11:20

1 Answers1

0

The template should be stored in the same directory as the flask script.It can then be used by passing the name of the html file to the render_template() function.

Also, there should be no blank lines between the decorator(@app.route('/')) and the def function.

Your code should look like this:

@app.route('/')
def index():
    with app.app_context(), app.test_request_context():
        template = render_template('index.html')
  • It did not work,and the index page is in the same directory inside the template/templates folder and even after removing the line between decorator and def function it is showing the same error – Alisha Aug 14 '20 at 11:55