-1

I'm attempting to get the invoice number from a button. This number changes with Jinja. I've looked at the following answer but it's not helping. Nothing is printing. Can someone please help?

How to get the value of a variable within an html tag in flask?

HTML

<form><th><Button class="btn btn-dark" name="invoice_no" value="{{ i.invoice_no }}">Select Invoice</Button></th></form>

Flask

if request.method == "POST":

    #  Retrieve invoice number from button
    if request.form.get('invoice_no'):
        invoice = request.form.get('invoice_no')
        print(invoice)
        print("print test")

Output is correct: invoice_no=3

INFO: 127.0.0.1 - - [24/Aug/2022 20:17:43] "GET /transactions?invoice_no=3 HTTP/1.1" 200 -
David James
  • 23
  • 1
  • 6
  • You pass variables within the URL as query parameters with a get request, not in the body of a post request. To get these values use `request.args`. – Detlef Aug 24 '22 at 19:27
  • I changed it to 'if request.args('invoice_no'):' and nothing changed. Also I've used request.form.get within the body of other pages and it works fine? – David James Aug 24 '22 at 19:33
  • Your log entry shows a GET request with url parameters. If you want to use post, it is necessary to assign the value `POST` to the `method` attribute of the form. – Detlef Aug 24 '22 at 19:35
  • Thank you for your time. This is what was missing. – David James Aug 24 '22 at 19:46

1 Answers1

0

Okay so don't forget to put method="post" within the form tag. Thank you Detlef.

David James
  • 23
  • 1
  • 6