Problem about 500 Internal Server Error in Python Flask
20,060
Whenever we receive 500 internal server error on a Python wsgi application we can log it using 'logging'
First import from logging import FileHandler,WARNING
then after app = Flask(__name__, template_folder = 'template')
add
file_handler = FileHandler('errorlog.txt')
file_handler.setLevel(WARNING)
Then you can run the application and when you receive a 500 Internal server error, cat/nano your errortext.txt file to read it, which will show you what the error was caused by.
Related videos on Youtube
Comments
-
Michael Nguyen almost 2 years
This is my Python code:
from flask import Flask, render_template app = Flask(__name__) @app.route("/profile/<name>") def profile(name): return render_template("index.html", name=name) if __name__ == "__main__": app.run()
and HTML code:
<!DOCTYPE html> <html> <head> </head> <body> Hello {{ name }} </body> </html>
And when I run the Python code, it shows on the browser that:
Internal Server Error The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.
I looked for the solution on Google as well as Youtube, but still can't fix it. Can someone help me with this? Thank you
Edit: so all I need to do is to fix this one line:
app = Flask(__name__, template_folder="template")
-
Charles R about 4 yearsCould you please switch to debug mode app.run(debug=True) to be able to give us more details ?
-
Michael Nguyen about 4 years@Charles R now it says that "jinja2.exceptions.TemplateNotFound jinja2.exceptions.TemplateNotFound: index.html"
-
Charles R about 4 yearsso your temple might not be in the right directory. By default template_forders="templates" with a plural S, you specified template without S
-
-
Michael Nguyen about 4 yearsI followed everything you said, yet it's still not working, the browser keep saying that "Internal Server Error The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application."