Retrieve ID from submit button using Post

Hi greetings

Was wondering if we could retrive id from submit button. The problem is that i dont want it in the values. I have many attachments and with it next to it a delete button . I just want to “Delete” to read as “Delete” . So id was what i assumed would be the best way to hold the identifier for which attachment to delete. Its just that i cant find the code from Django that actually gets the id in views ?

So in my html page i have the following

{% for X in object_list %}

                          <td><a class="article-title" href={{ X.Attachment.url }}>{{ X.Attachment }}</a></td>
                          <td>

In my views i do the following

if (self.request.POST.get(‘Delete’)):

deletevalue = self.request.POST.get (‘Delete’) # gets values , but i just want the id of the submit button pressed

The problem with that the values for multiple delete buttons are the same . I want the id of that submit button . I dont want to have it in values as it clutters the UI with Delete145, Delete146 etc .

I’m sorry, I’m a bit confused by what you’re trying to say here.
First you’re talking about buttons, but your example shows an a tag with a link. How does that relate to the rest of your post?

Aside from that, a button element submits the value attribute, not the id, nor the displayed value inside the button. You can create as many different buttons as you wish.
It’s the input element that submits the value without the option of identifying a separate display value.

Sorry , seems like something is a miss

i had this

even when i hit edit it had it in original. Let me try again without the form-group

Ok i cant seem to render an input type submit in this forum. It shows up in my original but not when i post

Ok i guess the issue i want to get id values from post from an input type=submit button. Not using javascript. Seems like it cant be done or i am missing something again

You need to surround blocks of code with lines of three backtick - ` characters. (A line of ```, then your code, then another line of ```.) Or, if it’s just one line (or part of one line), you can use one backtick `, then the text, then another backtick - looks like this.

Correct. See the referenced docs linked in my previous reply.

Ok thanks again, just have to use the javascript way i guess. The issue is i dont want delete buttons to have various labels on it
‘’’
{% for X in object_list %}

                        <tr>

                          <td><a class="article-title" href={{ X.Attachment.url }}>{{ X.Attachment }}</a></td>

                          <td>

                            {% if Approver%}

                             

                            {%else%}

                            <div class="form-group"><input type="hidden" name="filepk" value={{ X.id }}></div>

                           

                            <div class="form-group"><input type="submit" id = {{X.id}} name="Delete" value="Delete" class="btn btn-outline-primary float-right "  /></div>

                            {% endif%}

                          </td>

                          </tr>

‘’’

That’s why the documentation I keep referring you to tells you to use a button element instead of an input element.

(Oh, and you need to use the backtick - `, not the apostrophe - '.)

ok got it, its better with buttons now