4

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")
4
  • 1
    Could you please switch to debug mode app.run(debug=True) to be able to give us more details ? Commented Mar 13, 2020 at 9:09
  • 1
    @Charles R now it says that "jinja2.exceptions.TemplateNotFound jinja2.exceptions.TemplateNotFound: index.html" Commented Mar 13, 2020 at 14:30
  • so your temple might not be in the right directory. By default template_forders="templates" with a plural S, you specified template without S Commented Mar 15, 2020 at 13:54
  • A 500 there is a very generic something went wrong error there are a million possible answers to this Commented May 2, 2024 at 0:18

4 Answers 4

3

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 errorlog.txt file to read it, which will show you what the error was caused by.

Sign up to request clarification or add additional context in comments.

Comments

1
  1. You must not had an empty line beetween @app.route("/profile/<name>") and def profile(name):

  2. You have to set the html file in a folder called templates.

  3. You have to set the templates folder and run.py in the same folder

2 Comments

I 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."
I have the same. All of sudden when I woke up this morning.
0

You can try this below by adding the type string in your @app.route :

@app.route("/profile/<string:name>")
def profile(name):
  return render_template("test.html", name=name)

Comments

0

I´ve found a solution: go into your task manager and if there are more than one "python " tasks running stop them all and rerun your programm!

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.