title: Django Pass parameters to Form, getting KeyError
body: <p>I'm trying to pass two parameters to initialize my form, I have tried different ways to achieve this but I get the same error over an over, this is the error that I'm getting (Traceback):</p>
  
  <pre><code>Traceback (most recent call last):
    File "C:\Users\jorge.lopez\.virtualenvs\Carros-ZVuxKBiy\lib\site-packages\django\core\handlers\exception.py", line 34, in inner
      response = get_response(request)
    File "C:\Users\jorge.lopez\.virtualenvs\Carros-ZVuxKBiy\lib\site-packages\django\core\handlers\base.py", line 115, in _get_response
      response = self.process_exception_by_middleware(e, request)
    File "C:\Users\jorge.lopez\.virtualenvs\Carros-ZVuxKBiy\lib\site-packages\django\core\handlers\base.py", line 113, in _get_response
      response = wrapped_callback(request, *callback_args, **callback_kwargs)
    File "C:\Users\jorge.lopez\.virtualenvs\Carros-ZVuxKBiy\lib\site-packages\django\views\generic\base.py", line 71, in view
      return self.dispatch(request, *args, **kwargs)
    File "C:\Users\jorge.lopez\.virtualenvs\Carros-ZVuxKBiy\lib\site-packages\django\views\generic\base.py", line 97, in dispatch
      return handler(request, *args, **kwargs)
    File "C:\Users\jorge.lopez\.virtualenvs\Carros-ZVuxKBiy\lib\site-packages\django\views\generic\edit.py", line 168, in get
      return super().get(request, *args, **kwargs)
    File "C:\Users\jorge.lopez\.virtualenvs\Carros-ZVuxKBiy\lib\site-packages\django\views\generic\edit.py", line 133, in get
      return self.render_to_response(self.get_context_data())
    File "C:\Users\jorge.lopez\.virtualenvs\Carros-ZVuxKBiy\lib\site-packages\django\views\generic\edit.py", line 66, in get_context_data
      kwargs['form'] = self.get_form()
    File "C:\Users\jorge.lopez\.virtualenvs\Carros-ZVuxKBiy\lib\site-packages\django\views\generic\edit.py", line 33, in get_form
      return form_class(**self.get_form_kwargs())
    File "C:\Users\jorge.lopez\Documents\Personal\Carros\carros\AC\forms.py", line 100, in __init__
      self.carro = kwargs.pop('carro')
  
  Exception Type: KeyError at /payments/addtoexistingweek/1/2020-W07
  Exception Value: 'carro'
  </code></pre>
  
  <p><strong>Update</strong></p>
  
  <pre><code>Exception Type: NoReverseMatch at /payments/addtoexistingweek/1/2020-W07
  Exception Value: Reverse for 'pagoaexistente' with no arguments not found. 1 pattern(s) tried: ['payments/addtoexistingweek/(?P&lt;carro&gt;[0-9]+)/(?P&lt;semana&gt;[-a-zA-Z0-9_]+)$']
  </code></pre>
  
  <blockquote>
    <p>urls.py</p>
  </blockquote>
  
  <pre><code>path('payments/addtoexistingweek/&lt;int:carro&gt;/&lt;slug:semana&gt;',
           views.AgregarPagoSemana.as_view(), name='pagoaexistente'),
  </code></pre>
  
  <blockquote>
    <p>views.py</p>
  </blockquote>
  
  <p><strong>Update</strong>    </p>
  
  <pre><code>class AgregarPagoSemana(CreateView):
  
      template_name = "AC/add_paymentexistingweek.html"
      model = Pagos
      form_class = AgregarPagoTransaccionExistente
  
      def get_form_kwargs(self):
          kwargs = super(AgregarPagoSemana, self).get_form_kwargs()
          kwargs['carro'] = self.kwargs.get('carro')
          kwargs['semana'] = self.kwargs.get('semana')
          return kwargs
  </code></pre>
  
  <blockquote>
    <p>forms.py</p>
  </blockquote>
  
  <pre><code>class AgregarPagoTransaccionExistente(forms.ModelForm):
  
      def __init__(self, *args, **kwargs):
          self.carro = kwargs.pop('carro')
          self.semana = kwargs.pop('semana')
          super(AgregarPagoTransaccionExistente, self).__init__(*args, **kwargs)
  
      class Meta:
          model = Pagos
          fields = ('carro', 'pago', 'fecha', 'semana', 'renta')
          widgets = {'fecha': forms.DateInput(attrs={'type': 'date'}),
                     'semana': forms.DateInput(attrs={'type': 'week'})
                     }
  </code></pre>
  
  <p>I don´t know if I'm understanding the error correctly and 'carro' is not getting the value.</p>