northben
northben

Reputation: 5588

Why must I specify context_object_name in my DetailView?

I'm new to Django (using version 1.5.1), recently completed the official Django tutorial. Now I'm making my own little app, and encountered something that I can't figure out.

I have a DetailView generic view, and have set the attribute model = Transaction. In my template, I can access fields on the model with {{ object.payee }}. However, I can't use {{ Transaction.payee }} unless I set context_object_name = 'Transaction' in my view.

According to the docs, it looks like this should work, and it worked fine in the official tutorial. What am I doing wrong?

Upvotes: 1

Views: 1275

Answers (1)

jpic
jpic

Reputation: 33420

According to the docs you linked:

For example, the model Article would have context object named 'article'

So, for Transaction, the context object would be named transaction.

Upvotes: 2

Related Questions