django-select2-forms可在admin中使用,但不能在模板中使用。抛出Django TypeError

时间:2019-02-19 14:49:15

标签: python django

运行服务器会引发Django TypeError: render()收到了意外的关键字参数“ renderer”

我的表格.py

class UserUpdateForm(forms.ModelForm):
    class Meta:
        model = User
        fields = ['username', 'first_name', 'last_name']
class ProfileUpdateForm(forms.ModelForm):
    class Meta:
        model = Counsellee
        fields = ['twitter_handle', 'categories', 'image', 'dob', 'gender', 'address', 'phone_number', 'bio', 'interests', 'active']
        widgets = {
        'dob': forms.TextInput(attrs={'type': 'date'}),
        'bio': forms.Textarea(attrs={'rows':3}),
        'interests': forms.Textarea(attrs={'rows':3}),
    }

我的views.py

@login_required
def profile_update(request):
    if request.method == "POST":
        u_form = UserUpdateForm(request.POST, instance = request.user)
        p_form = ProfileUpdateForm(request.POST, request.FILES, instance = request.user.counsellee)
        if u_form.is_valid() and p_form.is_valid():
            u_form.save()
            p_form.save()
            messages.success(request, f'Your profile details have been updated successfully!')
            return redirect('counsellee-home')
    else:
        u_form = UserUpdateForm(instance = request.user)
        p_form = ProfileUpdateForm(instance = request.user.counsellee)

context = {'u_form': u_form, 'p_form': p_form}
return render(request, 'counsellees/profile.html', context)

我的模型。py

class Counsellee(Profile):
    user = models.OneToOneField(User, on_delete=models.CASCADE, related_name = 'counsellee', null=True)
    categories = select2.fields.ManyToManyField(Category)
    interests = models.TextField(null=True, blank = True)
    twitter_handle = models.CharField(max_length=120, null=True) 
    active = models.BooleanField(default=True, null=True)

该小部件在管理面板中工作正常,但在实际网站上却无法正常工作。 我遵循了发现here的自述文件,但根本没有任何工作

1 个答案:

答案 0 :(得分:0)

尝试将其添加到render()函数

attrs =无,渲染器=无