-1

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)
Martin
  • 9
  • 4

1 Answers1

0

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.

Matteo Bianchi
  • 434
  • 1
  • 4
  • 19