title: Django: Change value in request.POST to 0 if empty
body: <p>I have the following form:</p>
  
  <p><a href="https://i.stack.imgur.com/T5WoG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/T5WoG.png" alt="enter image description here"></a></p>
  
  <p>When one of the tickets is empty, my form sends me an error with that every field is required, now I am trying to check if the form value is empty, if it's empty I want to change it to <code>0</code>, so <code>form.is_valid()</code> can be true.</p>
  
  <p>The attached code doesn't work. It says <code>string index out of range</code>.</p>
  
  <pre><code>   def reserve_ticket(request):
          if request.method == 'POST':
              quantities = request.POST.getlist('quantity')
  
              for i in range(len(quantities)):
                  if not request.POST['quantity'][i]:
                      request.POST['quantity'][i] = 0
  
              form = ReserveForm(request.POST)
              if form.is_valid():
                  print("Hello world")
                  return HttpResponse("Hello world")
          else:
              return HttpResponse("Back to homepage")
  </code></pre>