0

I am obviously victim of some dark magic...

Here is a template that I render :

context = Context({'my_cube': c})
template = Template(
    '{% load cube_templatetags %}'
    '{{ my_cube|inspect }} {{ my_cube.measure }}'
)

Here is the implementation of the inspect filter :

def inspect_object(obj):
    return obj.measure()

Here is what the rendering gives me :

>>> template.render(context)
u'6 None'

Does anyone know why the hell does the {{ my_cube.measure }} is not rendered properly, while obviously the function call is successful ???

NB : the measure function does no magic, no internal state is changed, I tested and it gives the same result each time, I also tested to put the inspect before the {{ cube.measure }}.... doesn't change anything. I have absolutely no clue on what's going on...

EDIT : I know where it seems to be coming from. But it is still strange. For some reason, my object's attribute are not resolved by template.Variable :

>>> Variable('measure').resolve(c) == None
True
>>> Variable('testitesti').resolve(c) == None
True
>>> c.testitesti()
68
#implementation of testitesti :
def testitesti(self):
    return 68

2 Answers 2

2

Well... I found the damn thing !

The object I was trying to render had a __getitem__ method that was just empty, so dictionnary indexing worked on this object (no error thrown), so of course the function call was not made !

Sign up to request clarification or add additional context in comments.

Comments

0

Inspect is being registered as a filter, yep? I'm assuming so else the whole template would choke. Is there a possible reserved word clash? inspect is a pretty loaded term, after all. Have you tried renaming that filter to something else?

1 Comment

Actually, this 'inspect' filter is just a debug filter that I wrote, after I observed the bug before... Plus, it would be a weird coincidence that there is a clash of names, but .... tadaaaa : I am still getting the expected value ! But I try ...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.