我能够使用基于类的视图格式实现自动完成灯功能:
class UserAccountsUpdate(UpdateView):
context_object_name = 'variable_used_in `add_user_accounts.html`'
form_class = AddUserAccountsForm
template_name = 'add_user_accounts.html'
def add_user_institution_details(request):
###code###
使用此表格:
class AddUserAccountsForm(autocomplete_light.ModelForm):
required_css_class = 'required'
name = forms.CharField(
required=True,
widget=autocomplete_light.TextWidget('InstitutionAutocomplete'),
label="",)
class Meta:
model = Institution
autocomplete_fields = ('name')
fields = ('name',)
使用urls.py:
url(r'^profile/add_user_accounts/', UserAccountsUpdate.as_view(), name='add_user_accounts'),
但是,我正在尝试在基于类的视图中调试我的代码(即add_user_institution_details)。我决定直接调用方法来改变代码。
所以将视图更新为:
def add_user_institution_details(request):
context_object_name = 'variable_used_in `add_user_accounts.html`'
form_class = AddUserAccountsForm
template_name = 'add_user_accounts.html'
if request.method == 'POST':
form = AddUserAccountsForm(request.POST)
# check whether it's valid:
if form.is_valid():
### code ###
并将urls.py更新为:
url(r'^add_details', add_user_institution_details),
由于某些原因,在第二个实现中,自动完成搜索框已完全消失。我错过了什么?