'displaying flask input() to a html template [duplicate]

how can i display an input to my web application? Ive tried many ways but not succesfully...

import random
import re
from flask import Flask, render_template

app = Flask(__name__)
app.debug = True


@app.route("/")
def index():
    return render_template("play.html")


@app.route("/hangman")
def hangman():
    answer = input("Hi, wanna play? Y/N: ")
    return render_template("game.html", answer=answer)


Solution 1:[1]

In game.html template you should put an input tag:

<form method="post" action="/want-to-play">
    <input type="text" placeholder="Do you want to play?" />
    <input type="submit" value="OK"/>
</form>

Then just put an endpoint /want-to-play in your flask app with what you want to do.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Matteo Bianchi