我的班级看起来像这样
class Foo():
x = attrib()
y = attrib()
f = Foo(x=1, y=2)
Run Code Online (Sandbox Code Playgroud)
我的模板看起来像
<html>
<body>
<span>{{x}}</span> -> instead of this I want to use foo.x
<span>{{y}}</span> -> instead of this I want to use foo.y
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
我用来template.render(**attr.asdict(f))渲染它。相反,我只想通过template.render(f)并使用{{f.x}}和{{f.y}}
有没有办法做到这一点?我不断遇到错误
vars = dict(*args, **kwargs)
TypeError: 'Foo' object is not iterable
Run Code Online (Sandbox Code Playgroud)