0

Base URL:

path('api/product/',
include(('store.urls', 'store'),
namespace='api-product')),

Store URL:

path('invoice-pdf-get/',
invoice.InvoiceToPdf.as_view(),
name='invoice-pdf-get'),

HTML:

<html>
<body>
<form method="get" action="{% url 'api-product:invoice-pdf-get' %}?R={{ invoice.invoice_unique_number }}">
<input type="submit" value="Generate PDF">
</form>
</body>
</html>

When I hit the button, I get the url in browser as:

http://localhost:8000/api/product/invoice-pdf-get/?

Where as expecting:

http://localhost:8000/api/product/invoice-pdf-get/?invoice_number=SOMEKEY

Though if I submit a hidden type input via form, I get the expected result
but I was reading: Daniel Roseman SO answer. to pass parameter via GET.
Though inspect shows the URL (see image) but why am I not getting expected result?

form url

Aashish Gahlawat
  • 409
  • 1
  • 7
  • 25

1 Answers1

1

When a form is submitted via GET, the values in the form are sent as the querystring. This overrides any querystring in the action URL. See this SO answer for example.

You should put your value as a hidden input in the form itself.

<form method="get" action="{% url 'api-product:invoice-pdf-get' %}">
  <input type="hidden" name="R" value="{{ invoice.invoice_unique_number }}">
  <input type="submit" value="Generate PDF">
</form>
Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895