Methods (key(), name(),...) are converted into propertie in a template.

0 views
Skip to first unread message

Sylvain

unread,
Jun 4, 2008, 10:45:53 AM6/4/08
to Google App Engine
Hi,

How is it possible that the "methods" (key(), Name(),...) are
converted into "properties" in a template.

I've an easy example :

In my python file i've an Image model :

Class Image(db.Model):
label = db.StringProperty()

and then i can do :

im = Image()
logging.info(im.key().name()) <--- it works
logging.info(im.key.name) <--- error "AttributeError"

but in my template, if i send the object 'im' (as dic in the render
function) i can do :
{{ im.key.name }} <-- it works, i've got the key_name
{{ im.key().name() }} <-- error "TemplateSyntaxError"

How is it possible that the template can convert Methods into
Properties ? ;)

Thank you

Tom Offermann

unread,
Jun 4, 2008, 10:56:53 AM6/4/08
to google-a...@googlegroups.com
On Wed, Jun 4, 2008 at 7:45 AM, Sylvain <sylvain...@gmail.com> wrote:

> How is it possible that the template can convert Methods into
> Properties ? ;)

That's a feature of the Django Templates.

From the Django docs:

Technically, when the template system encounters a dot, it tries the
following lookups, in this order:

Dictionary lookup
Attribute lookup
Method call
List-index lookup

http://www.djangoproject.com/documentation/templates/

Hope that helps.

Tom

--
Blog: http://offermann.us/

Sylvain

unread,
Jun 4, 2008, 11:12:38 AM6/4/08
to Google App Engine
So... it was not a miracle :)

Thank you for your help.

Regards.

Sylvain




On Jun 4, 4:56 pm, "Tom Offermann" <tofferm...@gmail.com> wrote:
Reply all
Reply to author
Forward
0 new messages