相关疑难解决方法(0)

Django:将变量从get_context_data()传递到post()

该变量在内部定义,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()

python django

3
推荐指数
1
解决办法
3032
查看次数

标签 统计

django ×1

python ×1