更改Djangohays中的默认视图

2024-04-24 22:44:21 发布

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

我不熟悉django&haystack。我按照haystack网站上提供的示例教程,找到了如何执行基本搜索的方法。我可以得到输出值,但页面显示不正确。Haystack的默认形式是searchForm,但在我的例子中,默认形式是ModelSearchForm。我不知道为什么以及如何改变它。在

这是我的搜索.html第页。在

<form method="get" action=".">
  <table>
    {{ form.as_table }}
    <tr>
      <td>&nbsp;</td>
      <td>
        <input type="submit" value="Search" class="btn btn-default">
      </td>
    </tr>
  </table>
</form>

在我的搜索页面中,haystack总是显示一个默认表单。它有预定义的标签,它总是用一个复选框显示模型名,我不知道它从哪里显示这些值,以及如何修改这些值。在

我的搜索_索引.py文件

^{pr2}$

我的模型.py文件

from django.db import models
from django.utils.encoding import smart_unicode


class SignUp(models.Model):
    first_name = models.CharField(max_length = 120,null = True, blank= True)
    last_name = models.CharField(max_length = 120,null = True, blank= True)
    email = models.EmailField()
    timestamp = models.DateTimeField(auto_now_add = True, auto_now = False)
    update = models.DateTimeField(auto_now_add = False, auto_now = True)

    def __unicode__(self):
        return smart_unicode(self.email)

我想增加一个形象,以便更有效地沟通,但由于声誉不佳而无法沟通。:(


Tags: djangoformtrueautomodelstableunicode页面
1条回答
网友
1楼 · 发布于 2024-04-24 22:44:21

您可以在中更改窗体类和视图类网址.py. 比如:

from haystack.views import SearchView, search_view_factory
from haystack.forms import HighlightedModelSearchForm

urlpatterns = patterns('',
    # Examples:
    # url(r'^$', 'mamotwo.views.home', name='home'),
    # url(r'^blog/', include('blog.urls')),
    url(r'^search/', include('haystack.urls')),
    url(r'^mysearch/$', search_view_factory(view_class=SearchView, form_class=HighlightedModelSearchForm), name='mysearch'),
    url(r'^admin/', include(admin.site.urls)),
)

但我也是草堆新手。如果您检查此代码haystack demo或此视频haystack demo video,则更好

相关问题 更多 >