简体   繁体   中英

Django - referencing value from template in views.py

I have a Pandas dataframe that I am displaying as an HTML table. I turned the first column of that table into a column of clickable buttons that return a unique value and link to a webpage with information regarding the selected topic.

The col. was turned into a button with the following format:

'<button type="submit" name="info" value=' + df['Name:'] + '>More Info</button>'

However, in order to display the unique page when the button is clicked I need to be able to reference the button "value"

I have tried referencing the button value from my view in the following ways:

if request.POST.get('info', ''):
    value = info.value
    return redirect('detail')

if request.POST.get('info'):
    value = value
    return redirect('detail')

However, neither "value" or "info" can be called.

Does anyone know how I can reference the value of the button from my views.py?

edit:

I also tried the following:

if request.POST.get('info'):
    value = request.POST.get('value')
    return redirect('detail')

No error but it returns the value of value as "None"

Just double check if your button is inside of "form" tag, that is the only way to the buttons value got send through. If it doesn't work I think you should be able to get value if you change your "button" to an input tag with type = "submit"

Let me know if it works!

Try this:

in HTML

<input type="submit" value="hello" name="info">

in.py

value=request.POST.get('info')
print(value)

it works for me, try and if ot works the problem might be in value you are assigning

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM