>{{ foo }}{{ bar }} Now...">

How to get checkbox value in django?

<tr name="item">
        <td><input type="checkbox" ></td>
        <td>>{{ foo }}</td>
        <td> {{ bar }} </td>


</tr>

Now, I want django views to request.POST.getlist('item')return the value of ie fooand bar. But it returns null.

+3
source share
4 answers

I'm not sure that I understand everything that you requested, but if you want to get "foo" and "bar" when the user submits the form, you will have to add them to the form element, for example, hidden or text fields (depending on if the user can change them or not).

The server will not receive the entire DOM when submitting the form.

In addition, you will need to find a way to indicate which flag belongs to foo and bar.

+2
source

, , , , , , ...

<input type="checkbox" name="cb1" />

, :

queryset = {'cb1': 'on'}

:

queryset = {}

, :

if 'cb1' in queryset: 
    "item is selected"
else:
    "item is not selected"
+6

. foo bar - . , , , -. Django.

+4

, simle html. foo bar "value" , . , .

<tr name="item">
        <td><input type="checkbox" name="item" value="{{foo}},{{bar}}"></td>
        <td>>{{ foo }}</td>
        <td> {{ bar }} </td>


</tr>
0

Source: https://habr.com/ru/post/1780872/


All Articles