0

When I construct the URL for a link with parameters, parameter value in link address shows up as HTML form instead of value.

This is how I am generating the link in my template:

<a class="btn btn-success btn-block" href="{% url 'facility_page' facility_id=facility.id %} "  role="button">Edit</a>

This is how link address shows up:

http://127.0.0.1:8000/facility/(%3FP%3Cinput%20type=%22hidden%22%20name=%22facility-0-id%22%20value=%221%22%20id=%22id_facility-0-id%22%3E%5B0-9%5D+)/

I was expecting the link to look like this:

http://127.0.0.1:8000/facility/1

What am I doing wrong here?

urls.py

# path('facility/<int:facility_id>/', facility, name='facility_page'),
path('facility/<int>/', facility, name='facility_page'),
Asdfg
  • 11,362
  • 24
  • 98
  • 175
  • Your output does not match the code you say you are using to vegetate it. Where is that "input" coming firm? – Daniel Roseman Aug 14 '18 at 20:55
  • that's the thing. There is no input defined for `id` field explicitly in `forms.py`. `id` being internal primary key, django generates the hidden field and that is what shows up in the link address. If i replace `facility.id` with `facility.name`, it shows up as input for name field that I have in `forms.py`. No matter what field I use, it shows up as HTML and not as the value of that field. – Asdfg Aug 14 '18 at 20:58
  • I uninstalled django 2.1. Installed django 2.0. changed `facility.id` to `facility.id.value`. It worked. Uninstalled django 2.0. reinstalled django 2.1. It is still working. I have no idea why it is working now as I had tried `facility.id.value` before as well and it did not work. – Asdfg Aug 14 '18 at 21:43

0 Answers0