Reputation: 93
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")
Upvotes: 4
Views: 42445
Reputation: 1
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!
Upvotes: 0
Reputation: 45
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.
Upvotes: 3
Reputation: 1661
You must not had an empty line beetween
@app.route("/profile/<name>")
and def profile(name):
You have to set the html file in a folder called templates.
You have to set the templates folder and run.py in the same folder
Upvotes: 1
Reputation: 1767
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)
Upvotes: 0