Friday, March 25, 2016

Django tutorial part 3 - question_id vs


In trying to update my templates after I successfully finished part 3 of the tutorial, I found that I could write something like
<p>You're looking at the results of question {{ }}: "{{ question.question_text }}"</p>
and get: You're looking at the results of question 1: "What's up?"

However, if I write
<p>You're looking at the results of question {{ question.question_id }}: "{{ question.question_text }}"</p>
I get: You're looking at the results of question : "What's up?"

I think the answer is that "The template system uses dot-lookup syntax to access variable attributes. In the example of {{ question.question_text }}, first Django does a dictionary lookup on the object question."  And "id" is an attribute of the question object.  But if that's the case, then why is "question_id" used everywhere else (,  Is it because we *define* the question_id parameter by the pattern of the incoming request in  In other words, if we changed ?P<question_id> to ?P<my_favorite_number>, then we would be writing our views like this:
def detail(request, my_favorite_number):
= get_object_or_404(Question, pk=my_favorite_number)
but still referencing the id as {{ }} in our templates?

Hmm, I think I might have answered my own question, but I definitely thought I had exhausted my resources before deciding to write this post. ; )

Thank you,


You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To post to this group, send email to
Visit this group at
To view this discussion on the web visit
For more options, visit

No comments:

Post a Comment