You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Wagtail中get_context无法添加/访问上下文变量问题求助

问题

我可以在页面的serve方法中向context添加变量,并在页面模板中获取该上下文变量,但无法通过get_context方法添加上下文变量,或者无法在页面模板中访问这些变量。我希望通过get_context函数添加1-2个变量,并在页面模板中访问它们。

相关代码
# 如果request.user已认证且已注册该活动
# 将此状态存入context
# ###---看起来这个方法没有把变量加入context,
# ###---或者就算加了,模板里也访问不到--###
# def get_context(self, request, *args, **kwargs):
#     # pdb.set_trace()
#     context = super(EventPage, self).get_context(request, *args, **kwargs)
#     if request.user.is_authenticated:
#         # pdb.set_trace()
#         for attendee in self.event.eventattendee_set.all():
#             if attendee.email == request.user.email:
#                 # 用户是该活动的参与者
#                 context["is_attendee"] = True
#                 break
#     context["hello"] = "hello"
#     return context

内容的提问来源于stack exchange,提问作者Spinoza GL

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.13 02:15:36