1

How to use input function with flask in Python, to get a user input and then send response based on that response. Trying to do this continuously something like dialogue-flow approach .

Trying to expose this command line terminal to capture user input capture in UI

#Below is the code
df_final = pandas_dedupe.dedupe_dataframe(df,['Company'])
#Below is the resultant output which get displayed in terminal which asks for user response. 
#I'm trying to expose this to user and get his response.
Company : reliance captal

Company : reliance captive

0/10 positive, 0/10 negative
Do these records refer to the same thing?
(y)es / (n)o / (u)nsure / (f)inished
  • Have you tried using a form that sends a POST request to the server along with the command data? You can use AJAX to avoid re-rendering. – adrianp Jun 23 '20 at 14:55

1 Answers1

0

templates/contact.html

<form action="/contact" method="POST">
  <textarea type="text" name="msg"></textarea>
  <label>Messege</label>
  <button type="submit" class="button buttonBlue">
  Submit
  </button>
</form>

app.py
Data is stored in the msg variable and you can send a response based on that

@app.route('/contact', methods=['GET', 'POST'])
def contact():
    if request.method == 'POST':
        msg = request.form.get('msg')
    return render_template("contact.html")

hyper-neutrino
  • 5,272
  • 2
  • 29
  • 50
Programmer Gaurav
  • 449
  • 1
  • 5
  • 16
  • 1
    Thanks Gaurav, but issue is that I'm modifying the source code of an library which gets user input on command terminal using input function. I'm trying to capture that command terminal input into UI. – user3319471 Jun 23 '20 at 14:40