我已经有了一个基本的django haystack搜索表单,但现在我正在尝试创建一个自定义的搜索表单,其中包含几个要过滤的额外字段。在
我遵循了Haystack文档中关于创建自定义表单和视图的内容,但是当我试图查看表单时,我只能得到错误:
ValueError at /search/calibration/
The view assetregister.views.calibration_search didn't return an HttpResponse object. It returned None instead.
基于SearchForm不应该返回HttpResponse对象吗?在
在表单.py在
^{pr2}$在视图.py在
from .forms import CalibrationSearch
from haystack.generic_views import SearchView
from haystack.query import SearchQuerySet
def calibration_search(SearchView):
template_name = 'search/search.html'
form_class = CalibrationSearch
queryset = SearchQuerySet().filter(requires_calibration=True)
def get_queryset(self):
queryset = super(calibration_search, self).get_queryset()
return queryset
在网址.py在
from django.conf.urls import include, url
from . import views
urlpatterns = [
....
url(r'^search/calibration/', views.calibration_search, name='calibration_search'),
....
]
Haystack的
SearchView
是一个基于类的视图,添加url条目时必须调用.as_view()
类方法。在相关问题 更多 >
编程相关推荐