-1

I am trying to run this Flask project, put it's not working. Does anyone know why?

The .py file:

from flask import Flask, render_template

app = Flask(__name__)


@app.route("/")
def hoofdpagina():
    return render_template("afvink2.html")


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

The HTML file:

<!DOCTYPE html>
<html>
<body onunload="Reset()"  style="background-color:Pink;">
<head>
                <title>Messenger </title>
        </head>

        <h3>Messenger</h3>
Messagebox:<br> <textarea id="chatbox" cols="50" rows="5"></textarea> <br><br>
<br><input type="text" id="P1" value="ADI" ><input type="text" id="first"><button onclick="B1Function()">Send</button><br><br>
<br><input type="text" id="P2" value="JS" > <input type="text" id="second"><button onclick="B2Function()">Send</button>


<script>
function B1Function() {
    document.getElementById("chatbox").value += document.getElementById("P1").value ;
    document.getElementById("chatbox").value += ": " ;
    document.getElementById("chatbox").value += document.getElementById("first").value ;
    document.getElementById("chatbox").value += "\r"
    document.getElementById("first").value = ""

}
function B2Function() {

    document.getElementById("chatbox").value += document.getElementById("P2").value ;
    document.getElementById("chatbox").value += ": " ;
    document.getElementById("chatbox").value += document.getElementById("second").value ;
    document.getElementById("chatbox").value += "\r"
    document.getElementById("second").value = ""

}
function Reset() {
    document.getElementById("Berichtenbox").value = ""
    document.getElementById("first").value = ""
    document.getElementById("second").value = ""

}
</script>

</body>
</html>

The error:

C:\...\...\...\
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
127.0.0.1 - - [12/Jun/2017 12:12:07] "GET / HTTP/1.1" 500 -

The page http://127.0.0.1:5000/ says:

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.

Does anyone know how I can fix this? Thanks!

lakeviking
  • 322
  • 1
  • 6
  • 18

2 Answers2

1

Your project structure should be this.

├── app.py
└── templates
    └── afvink2.html

render_template method by default looks at the templates directory.

You can also configure the directory of templates to views or public

by simply mentioning the parameter in flask

app = Flask(__name__, template_folder="views")
app = Flask(__name__, template_folder="path/to/whatever")

Do check the configuration flask provides. Their documentation is pretty neat.

Team Kitsune
  • 101
  • 1
  • 7
0

Flask will look templates in the "templates" directory. Move your html template into the templates dir. It should work

Hari Roshan
  • 344
  • 4
  • 10