我正在尝试在我的视图中输出表单字段。但我得到: django.forms.widgets.Select 对象在 0x7f631c2cef10而不是 html 选择元素
我的代码:
表格.py
class SearchForm(forms.Form):
def __init__(self, *args, **kwargs):
from house.models import COUNTRY_LIST, HOUSE_TYPES
from profile.models import Region
self.countries = forms.Select(choices=COUNTRY_LIST, attrs={'title': 'Страна','class': 'search-r-from-select style-select'})
self.type = forms.Select(choices=HOUSE_TYPES, attrs={'class': 'search-r-from-select style-select'})
super(SearchForm, self).__init__(*args, **kwargs)
视图.py
def search_view(request):
from house.models import House
from house.forms import SearchForm
if request.GET.get('initSearch', False):
found_houses = House.get_search_result(request.GET)
search_form = SearchForm(request.GET)
else:
search_form = SearchForm()
return render_template(request, 'house/search.html', {
'search_form': search_form
})
房子/搜索/html
{{ search_form.countries }}