该变量在内部定义,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?
Run Code Online (Sandbox Code Playgroud)
将bar变量传递给的方式是post()什么?
试图将其保存为FooView的字段并通过进行访问self.bar,但这并不能解决问题。self.bar被看不到post()