Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

template renderer renders properties strangely #120

Open
granders opened this issue Oct 21, 2015 · 1 comment
Open

template renderer renders properties strangely #120

granders opened this issue Oct 21, 2015 · 1 comment

Comments

@granders
Copy link
Contributor

Refactoring a field into a property can lead to surprising results when rendering

class C(TemplateRenderer):
  x = 2

class D(TemplateRenderer):
  @property
  def x(self):
    return 2

c = C()
d = D()
c.render_template("{{x}}")  # "2"
d.render_template("{[x}}")  # "<property ob... 0x101300e68>"

Cause: @propertys show up in the class dict as a property object, but not in the instance dict, and TemplateRenderer uses these dicts when rendering. So the computed property value isn't visible to the render method.

@ewencp
Copy link
Contributor

ewencp commented Oct 21, 2015

There's probably a good solution to this somewhere in Jinja itself -- I'd dig around in their code (or example code) to see if there's a better approach for passing a full object as the context but also providing overrides/extensions via extra parameters to the render method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants