Getting __init__() got an unexpected keyword argument 'instance' with CreateView of Django

后端 未结 4 1631
无人及你
无人及你 2020-12-10 10:01

Some details:

Request Method: GET
Request URL: http://localhost:8080/user/create
Django Version: 1.5.1
Exception Type: TypeError
Exception Value: ____init__         


        
4条回答
  •  遥遥无期
    2020-12-10 10:34

    I override __init__() method incorrectly, without initial arguments, as show below

    class MyForm(forms.ModelForm):
        ...
        def __init__(self):
            super(CaseForm, self).__init__()
            ...
    

    And get this error as result

    TypeError at /case/create

    __init__() got an unexpected keyword argument 'initial'

    To fix it, I set arguments to __init__() and pass them when call super class __init__(), see result below

    class MyForm(forms.ModelForm):
        ...
        def __init__(self, *args, **kwargs):
            super(CaseForm, self).__init__(*args, **kwargs)
            ...
    

提交回复
热议问题