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

后端 未结 4 1634
无人及你
无人及你 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:35

    I solved a similar error I got when trying to save a form to a database. "Report() got an unexpected keyword argument 'summary'"

    The problem was that the field names in models.py and forms.py didn't match.

    In the class Report in models.py the name of the field was "summary_input", but in forms.py it was named "summary", so I changed the variable name in forms to match the one in models.

    # models.py
    class Report(models.Model):
        summary_input = models.TextField()
    
    # forms.py
    class ReportForm(forms.Form):
        summary = forms.CharField(widget=forms.widgets.Textarea)
        # changed to 
        # summary_input = forms.CharField(widget=forms.widgets.Textarea)
    

提交回复
热议问题