Django dict(request.POST.lists()) returns twice(normal, empty)

def tresults(request):
    ids = dict(request.POST.lists())
    data = ids['selected']
    msg = data.pop(0)


<form id = "{{ msg }}" action="tresults" method="POST">
             <input type="hidden" name="selected" value="{{ msg }}">
             <div class="table-responsive">
                 <table class="table table-bordered" id="dataTable" width="100%" cellspacing="0">

                            {% for guild in guilds %}
                                    <td>{{ }}</td>
                                    <td>{{ }}</td>
                                           {% csrf_token %}
                                           <input type="checkbox" name="selected" value="{{ }}"/>
                            {% endfor %}
         <a class="dropdown-item" href="#" onclick="document.forms['{{ msg }}'].submit();">Send</a>

and I getting from print(ids)

{'selected': ['61660a3afe554cfd1b4fe98f', '880716169986859039'], 'dataTable_length': ['10'], 'csrfmiddlewaretoken': ['OE9lhwbkU1KlKrDHiip1G6Yd5i9oOPS1bA0s2DapHY6RDbXc7UHc4KPd5jOlCLNm']}
[13/Oct/2021 07:55:57] "POST /posts/post/tresults HTTP/1.1" 302 0
Internal Server Error: /posts/post/tresults

I tried with various way like

request.POST.dict() <- returns with only one value

request.POST.copy() and dict(ids.iterlists()) or dict(ids) <- not working

I don't know why two dict printed and last one is empty. I want to fix this

Answers: 1

Answered by Marcus Aldrey, Oct. 13, 2021, 5:42 a.m.

You have

<input type="hidden" name="selected" value="{{ msg }}">


<input type="checkbox" name="selected" value="{{ }}"/>

both with name="selected", change the name of one of then