将 haystack 集成到我的应用程序中

发布于 2025-01-02 13:07:44 字数 645 浏览 2 评论 0原文

我已经为显示产品编写了一个自定义平台(例如没有购物车和运输的电子商务)

无论如何,我在 127.0.0.1/myapp/search 上启动并运行了 haystack,我可以执行搜索,结果完美返回,并且一切正常。

这是我的工作网址

http://dpaste.com/698413/

目前我的搜索文件,重定向到一个空的base.html(带有内容块)

http://dpaste.com/698414/

现在,您可以通过我的 urls.py 文件看到,我的产品是通过自定义 url + 视图条目加载的。

这会将我重定向到一个名为detail.html 的模板,其中包含(您猜对了)根据已加载的产品的详细信息。

现在,当我尝试将我的search.html 文件包含到我的detail.html(与我的/search 条目使用的相同)中时,代码无法正确呈现,它显示了表单方法,但没有其他内容。

我要问的是,如何才能将我的 haystack 搜索代码加载到我的detail.html 页面中。

谢谢。

I have written a custom platform for display products (like ecommerce with no carts and shipping)

Anywway, I have haystack up and running at 127.0.0.1/myapp/search, I can perform searches, the results return perfectly and all works as it should.

here is my working urls

http://dpaste.com/698413/

And currently my search file, which redirects to an empty base.html (with the content block)

http://dpaste.com/698414/

Now as you can see via my urls.py file, my products are loaded via a custom url + view entry.

This redirects me to a template called detail.html, which contains (you guessed it) detailed information according to what product has been loaded.

Now when I try and include my search.html file into my detail.html (the same one used with my /search entry) the code doesnt render correctly, it shows the form method, but nothing else.

What I am asking is, how can I get my haystack search code to load in my detail.html page.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

初相遇 2025-01-09 13:07:44

猜测渲染 details.html 模板时未设置 form 上下文变量。覆盖 DetailView 并为表单设置额外的上下文数据应该使表单显示在页面上,如下所示:

from haystack.forms import SearchForm

#in overriden DetailView
def get_context_data(self, **kwargs):
    #call super
    ctx['form'] = SearchForm() 
    return ctx

Guessing that form context variable is not set when details.html template is rendered. Override DetailView and set extra context data for form should make form to appear on page, something like this:

from haystack.forms import SearchForm

#in overriden DetailView
def get_context_data(self, **kwargs):
    #call super
    ctx['form'] = SearchForm() 
    return ctx
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文