Haystack 自定义表单字段未显示在模板中

Haystack custom form fields not showing in template

我想在 Haystack 表单中添加一个额外的字段,但由于某种原因,模板中的表单输出无法正常工作。

我没有显示额外的字段,而是得到了一些带有模型 select 字段的奇怪模板。我想要的只是一个 q 输入和 author.

的额外字段

forms.py

from django import forms
from haystack.forms import HighlightedSearchForm

class QuestionSearchForm(HighlightedSearchForm):
    author = forms.CharField(max_length = 100, required = False)

views.py

# Create your views here.
from haystack.generic_views import SearchView
from search.forms import QuestionSearchForm


class QuestionSearchView(SearchView):
    form_class = QuestionSearchForm
    template_name = 'search/search.html'

search/search.html

<form method="get" class="form-inline" action=".">
    <div>
        {{ form.as_p }}
        <input class="btn btn-primary" type="submit" value="Najdi"/>
    </div>
</form>

输出:

谢谢!

我认为 template_name 在您的 views.py 中应该是 template

看看 haystack Github page.

上的默认值 class SearchView