Я пытаюсь передать два параметра для инициализации своей формы, я пытался разными способами добиться этого, но я получаю ту же ошибку за овер, это ошибка, которую я получаю (Traceback):
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'
Обновление
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<carro>[0-9]+)/(?P<semana>[-a-zA-Z0-9_]+)$']
urls.py
path('payments/addtoexistingweek/<int:carro>/<slug:semana>',
views.AgregarPagoSemana.as_view(), name='pagoaexistente'),
views.py
Обновление
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
forms.py
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'})
}
Я не знаю, понимаю ли я ошибка правильно, и 'carro' не получает значение.