[Django]-TypeError: __init__() got an unexpected keyword argument 'widget'

0👍

Try this in your form.

Forms.py

        widgets = {
        'Title': forms.TextInput(attrs={'class': 'form-control','required':'required'}),
        'Description': forms.TextInput(attrs={'class': 'form-control','required':'required'}),
        'StartDate': forms.DateInput(attrs={'class': 'form-control', 'type': 'date','required':'required'}),
        'EndDate': forms.DateInput(attrs={'class': 'form-control', 'type': 'date','required':'required'}),
       }

3👍

You have your widgets and fields the wrong way around – DateField is a field and DateInput is a widget. So your form use forms.DateField(widget=forms.DateInput()). However, since DateField uses DateInput by default, you can drop the widget argument entirely:

class CustomertaskForm(forms.ModelForm):
    ...
    startdate=forms.DateField()
    enddate=forms.DateField()

As an aside, you can create the task by saving the model form. You don’t need to call Customertask.objects.create() manually:

if form.is_valid():
    tasksave=form.save()
    return HttpResponseRedirect('/customer/tasktable')

Leave a comment