Issue
So I was making a simple web application where you enter some text and it shows up on the screen, sort of like a chat screen.
My Python Code
import sys
from flask import *
app = Flask(__name__)
option_list = []
@app.route('/', methods=['POST', 'GET'])
def sessions():
if request.method == 'POST':
if request.form['message'] != '':
option_list.append(request.form['message'])
print(option_list, file = sys.stdout)
return render_template("session.html", option_list = option_list)
if __name__ == '__main__':
app.run(debug = True)
My HTML Code
<html>
<body>
<title>Text:</title>
<ul style="list-style-type:none;"></ul>
{% for o in option_list %}
<li>{{ o }}</li>
{% endfor %}
</ul>
<form action = "http://127.0.0.1:5000/" method = "post">
<p><input type = "text" name = "message" autocomplete="off" /></p>
<p><input type = "submit" name = sgnin value = "Send" /></p>
</form>
</body>
</html>
The logs and html both show that they are sending and receiving data. However, instead of printing the value of o
, it just prints o
. I'm pretty sure it's because of the HTML file. I'm sure this might be a rookie mistake, but any idea how to fix it?
Solution
I just re-ran my code and it's working as it should, although I have no idea how it fixed itself.
Answered By - Ismail Hafeez
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.