These views take an argument.
If we add this to urls.py,the browser accordingly returns different things.
For example, If we type "/polls/34/", it will run the detail() method and display "You're looking at question 34."
Each view is reponsible for 1. returning an HttpResponse object containing the content for the requested page, or 2. raising an exception such as Http404.
HttpResponse objects are your responsibility. Each view you write is responsible for instantiating, populating, and returning an HttpResponse. (It's like printing????)
render() combines a given template with a given context dictionary and returns an HttpResponse object with that rendered text.
Note that once we’ve done this in all these views, we no longer need to import loader and HttpResponse.
The render() function takes the request object as its first argument, a template name as its second argument and a dictionary as its optional third argument. It returns an HttpResponse object of the given template rendered with the given context.
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. Failing that, it tries an attribute lookup – which works, in this case. If attribute lookup had failed, it would’ve tried a list-index lookup.
Method-calling happens in the {% for %} loop: question.choice_set.all is interpreted as the Python code question.choice_set.all(), which returns an iterable of Choice objects and is suitable for use in the {% for %} tag.
question.choice_set.all은 해당 Question모델을 foreign key로 참조하는 모든 Choice 모델을 가져온다. forloop.counter는 for문이 얼마나 돌았는지 1부터 시작하여 1씩 증가하여 반환한다.
<li><a href="/polls/{{ question.id }}/">{{ question.question_text }}</a></li>
<li><a href="{% url 'detail' question.id %}">{{ question.question_text }}</a></li>