3π
β
If you access request.POST.get('key')
(or request.POST['key']
), you only get the last value associated with that key.
You access all values with the .getlist(β¦)
methodΒ [Django-doc]:
print(request.POST.getlist('the_choices'))
But normally you process data with the form itself, so:
form = MyForm(request.POST, request.FILES)
if form.is_valid():
print(form.cleaned_data['the_choices'])
This will also clean the data and return model objects, not their primary keys.
1π
use getlist
https://docs.djangoproject.com/en/4.0/ref/request-response/#django.http.QueryDict.getlist
try this
the_choices = request.POST.getlist('the_choices')
π€rahul.m
- [Django]-Django Forms: Validation message not showing
- [Django]-Django 1.6 HTTP_X_CSRFTOKEN header ignored if csrf cookie is missing
Source:stackexchange.com