Django Haystack自定义搜索表单

2024-09-30 04:36:52 发布

您现在位置:Python中文网/ 问答频道 /正文

我已经有了一个基本的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'),
    ....
]

Tags: djangofrompyimport视图表单searchreturn

热门问题