尝试为所有 django oscar 电子邮件模板添加额外的上下文变量。我让它工作的唯一方法是覆盖特定视图,如 ProfileUpdateView。这种方法看起来很乱,我不得不覆盖很多文件。有没有更好的方法来做到这一点?
2 回答
0
最终制作了一个自定义管理命令来手动完成,因为更改电子邮件模板的需要非常少见。
于 2015-10-27T09:17:45.030 回答
0
通过检查源代码,ProfileUpdateView
使用 Django 的基于类的 View FormView
,它又实现了get_context_data
允许在视图中注入额外数据的方法。您可以简单地创建一个包含 ProfileUpdateView 的视图并覆盖get_context_data
:
class MyProfileUpdateView(ProfileUpdateView):
...
def get_context_data(self, **kwargs):
context = super(MyProfileUpdateView, self).get_context_data(**kwargs)
context['somevar'] = SomeQueryMaybe.objects.all()
return context
于 2015-09-16T13:05:35.490 回答