如何为django-oscar添加mini_wishlist?

问题描述 投票:0回答:2

我在django-oscar的电子商务网站工作。我有心愿单的问题。我想在导航栏上添加mini_whislist。这看起来像奥斯卡的篮球。

我确实试过这个,但它只在愿望清单部分工作。

{% if wishlists %}
   {% for wishlist in wishlists %} 
       <span class="text-muted b">{{ wishlist.name }}</span>
       <span class="text-muted b">{{ wishlist.lines.count }}</span>
   {% endfor %}
{% else %}
    <img src="{% static "images/topview.png" %}">
    <span class="p-2 text-muted b">EMPTY</span>
{% endif %}

如何让它出现在每个页面上?

django django-oscar
2个回答
2
投票

在客户应用中创建上下文处理器 context_processors.py

def wishlists(request):
    if not (request.user and request.user.is_authenticated):
        return {}
    return {
        'wishlists': request.user.wishlists.all()
    }

并将其放入设置文件中

TEMPLATE_CONTEXT_PROCESSORS = (

    'customer.context_processors.wishlists',
)

然后你可以在任何地方使用愿望清单


1
投票

一个想法是将您为此功能编写的所有html放入HTML文件,然后在{% include 'your_file.html' %}中使用layout.html,放入base.html不是一个好主意,因为仪表板也扩展了相同的基本模板。

此外,请注意您必须在checkout / layout.html中执行相同操作,因为它们具有单独的结帐页面布局。

© www.soinside.com 2019 - 2024. All rights reserved.