0👍
✅
forms.Select
is a widget, it is not a Field
and it doesn’t have a widget
argument. This is what the error is reporting about. This is what you basically have:
>>> from django import forms
>>> forms.Select(widget=forms.Select)
Traceback (most recent call last):
File "<console>", line 1, in <module>
TypeError: __init__() got an unexpected keyword argument 'widget'
Instead, you meant to have a ChoiceField
with a Select
widget:
TableName = forms.ChoiceField(widget=forms.Select(attrs={'class': 'selector'}))
See also Daniel’s example here:
2👍
Another possibility when receiving this error message is that Django has different types of fields when dealing with db models and form models. Make sure that your includes are in the correct order; include forms AFTER models. If you do something along the lines of:
from models import *
from django.forms import *
This will force the Form’s field objects to be used instead of the Model’s field objects which DO have the widget
keyword.
👤Fydo
- [Answered ]-How to not start an EmberJs App with static assets present
- [Answered ]-Django Multiple db with read only
- [Answered ]-Django Split a charfield output which is seperated by ','(comma) into an array of strings.?
Source:stackexchange.com