【发布时间】:2015-01-21 17:12:08
【问题描述】:
该变量在get_context_view() 中定义,因为它需要id 才能访问正确的数据库对象:
class FooView(TemplateView):
def get_context_data(self, id, **kwargs):
---
bar = Bar.objects.get(id=id)
---
def post(self, request, id, *args, **kwargs):
# how to access bar?
# should one call Bar.objects.get(id=id) again?
将bar 变量传递给post() 的方法是什么?
尝试将其保存为 FooView 的字段并通过self.bar 访问它,但这并没有成功。 self.bar 没有被post() 看到
【问题讨论】: