Internal server error when running ex51.py

internal server error when running ex51.py

Ok.
But we need more information to be able to help.

  • When does this error occur?
  • Directly?
  • Or after start but as soon as you do something?
    The traceback use to point out where the problem are.
  • Have you tried to change something on this or around this row?
  • Have you Google this problem?
  • What answer do other get when posting this question?

If you dont find any useful you can of course put in your code here on this forum.

Paste your code between those ”code” words within square brackets.

[code]
 Paste your code in here. 
[/code]
from flask import Flask
from flask import render_template
from flask import request

app = Flask(__name__, template_folder="templates/")

@app.route("/hello", methods=['POST', 'GET'])
def index():
    greeting = "Hello World"

    if request.method == "POST":
        name = request.form['name']
        greet = request.form['greet']
        greeting = f"{greet}, {name}"
        return render_template("index.html", greeting=greeting)
    else:
        return render_template("hello_form.html")


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

thank you for taking the time to help

Hi @ailsagy.

I first must say there perhaps are some formating error when you put up your code.
If you didn’t. Please include your all of your code between

[code]
and
[/code]

I have never seen anything else than:

app = Flask( __name__)

and

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

When I have this structure:

ex51/
app.py templates/
                  index.html
                  hello_form.html

I got your code running when removing text in bold:

app = Flask( name, template_folder=“templates/”)
app.run(threaded=True)

I have never seen this before.
Is it necessary?

Hey @ailsagy, follow these instructions and turn on development mode:

http://flask.pocoo.org/docs/1.0/quickstart/#debug-mode

This will give you better output on what’s wrong.

A free service run by Zed A. Shaw for learncodethehardway.org.