django - fork 模板 django-oscars 后,仪表板不填充值

标签 django django-oscar

这是我的仪表板 view.py-

from django.views.generic import TemplateView
class IndexView(TemplateView):
    def get_template_names(self):
    if self.request.user.is_staff:
      return ['mytemplates/index.html']
    else :
      return ['dashboard/index_nonstaff.html','mytemplates/index.html']

因此,我成功地 fork 了应用程序并扩展了模板,但由于某种原因,仪表板上没有显示任何值

1

最佳答案

您定义了一个新的 IndexView,它不会子类 Oscar 的 IndexView - 因此模板无法找到任何相关上下文。您当前拥有的只是一个普通的 TemplateView ,与 Oscar 完全没有关系。

假设您已按照 fork the dashboard app 的说明进行操作,然后您需要继承 Oscar 的 IndexView:

from oscar.apps.dashboard.views import IndexView as CoreIndexView

# Note - you subclass CoreIndexView, not TemplateView
class IndexView(CoreIndexView):

    def get_template_names(self):
        if self.request.user.is_staff:
            return ['mytemplates/index.html']
        else:
            return ['dashboard/index_nonstaff.html','mytemplates/index.html']

参见this bit of the documentation其中解释了如何执行此操作。

也就是说,如果您只想覆盖模板(而不是任何 View 逻辑),那么实际上没有必要覆盖 View 。只需覆盖 Oscar 的模板 as described here - 这样您就可以将模板 yourproject/templates/dashboard/index.html 添加到您的项目中,该模板将优先于 Oscar 的默认模板加载。

关于django - fork 模板 django-oscars 后,仪表板不填充值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50647838/

相关文章:

python - 嵌入式 C PWM 调光器到 Django Web 应用程序

python - 在 Django 中打开 zip 文件中存储的照片时出错

django - Paypal 重定向问题

python - 限制仪表板用户 Django-Oscar (Sandbox Gateway App)

python - 从 Django-Oscar 扩展客户的 View

Django-Oscar 从管理面板取消注册一个类

Django:使用 Oauth2 和 SSL 时得到 403

python - 在共享主机上访问 Django Runserver

python - 卡住数据库以测试 Django 中的新功能

python - Django 和 Django 奥斯卡