[django] tutorial - 3,4

ใ…Žใ…Žยท2021๋…„ 6์›” 16์ผ
0

django

๋ชฉ๋ก ๋ณด๊ธฐ
3/8


๐Ÿ“Œ django

django tutorual


- part3

#polls/views.py 
#์ฒ˜์Œ์—


#ํด๋ผ์ด์–ธํŠธ๋กœ๋ถ€ํ„ฐ request๋ฅผ ๋ฐ›์œผ๋ฉด HttpResponse๋กœ ๋ฆฌํ„ด!

def detail(request, question_id):
    return HttpResponse("You're looking at question %s." % question_id) #response๋กœ ํด๋ผ์ด์–ธํŠธ์—๊ฒŒ ์ „๋‹ฌ

def results(request, question_id):
    response = "You're looking at the results of question %s."
    return HttpResponse(response % question_id)

def vote(request, question_id):
    return HttpResponse("You're voting on question %s." % question_id)
#polls/urls.py
from django.urls import path

from . import views

urlpatterns = [
    # ex: /polls/ , views.index(ํ•จ์ˆ˜)๋ฅผ ํ˜ธ์ถœ 
    path('', views.index, name='index'),
    # ex: /polls/5/ ,views.detail์„ ํ˜ธ์ถœ
    path('<int:question_id>/', views.detail, name='detail'),
    # ex: /polls/ 5/results/
    path('<int:question_id>/results/', views.results, name='results'),
    # ex: /polls/5/vote/
    path('<int:question_id>/vote/', views.vote, name='vote'),
] 
# <int:question_id>/vote/ ๋Š” ์žฅ๊ณ ์—์„œ ์ง€์›ํ•˜๋Š” urlํŒจํ„ด
# name์€ ํ…œํ”Œ๋ฆฟ์• ์„œ urlํŒจํ„ด ๋Œ€์‹  ์ด๋ฆ„์„ ์‚ฌ์šฉ
# question_id๋Š” view์˜ ํŒŒ๋ผ๋ฏธํ„ฐ์˜ question_id์™€ ์ผ์น˜๋˜์–ด์•ผํ•จ. 
  • view๋Š” HttpRespose ๊ฐ์ฒด๋ฅผ ๋ฐ˜ํ™˜ํ•˜๊ฑฐ๋‚˜ ๋˜๋Š” Http404๊ฐ™์€ ์˜ˆ์™ธ๋ฅผ ๋ฐœ์ƒ ์‹œํ‚จ๋‹ค.
#polls/views.py 

from django.http import HttpResponse

from .models import Question

# question ๋ฐ์ดํ„ฐ ์ค‘์—์„œ ์ถœํŒ์ผ์ž๋ฅผ ์ •๋ ฌํ•˜์—ฌ 5๊นŒ์ง€๋งŒ ๋ฐ์ดํ„ฐ๋ฅผ ๊ฐ€์ ธ์˜ค๊ณ , ์ฝค๋งˆ๋กœ ์—ฐ๊ฒฐํ•ด ์ŠคํŠธ๋ง์œผ๋กœ ๋งŒ๋“ค๊ณ 
def index(request):
    latest_question_list = Question.objects.order_by('-pub_date')[:5]
    output = ', '.join([q.question_text for q in latest_question_list])
    return HttpResponse(output)  #๊ทธ ๋ฌธ์ž์—ด์„ response

โžก๏ธ ์œ„์˜ ์ฝ”๋“œ๋Š” ํด๋ผ์ด์–ธํŠธ์—๊ฒŒ ๋ณด์—ฌ์ฃผ๋Š” ์ฝ”๋“œ๊ฐ€ view๋‚ด์— ์กด์žฌ. ํ•˜์ง€๋งŒ ๋””์ž์ธ ์ˆ˜์ • ์‹œ ํด๋ผ์ด์–ธํŠธ์—๊ฒŒ ๋ณด์—ฌ์ฃผ๋Š” ํŽ˜์ด์ง€ ์ˆ˜์ •์ด ์–ด๋ ค์›€ ๋”ฐ๋ผ์„œ ๋‚ด๋ถ€ ์กฐ์ง ๋‹ด๋‹น๊ณผ ๋””์ž์ธ ๋‹ด๋‹น์ธ templates๋ฅผ ๋ถ„๋ฆฌํ•ด์•ผํ•จ.

<!-- polls/templates/polls/index.html-->
<!-- ์•ฑ ์ด๋ฆ„์œผ๋กœ ๋””๋ ‰ํ† ๋ฆฌ๋ฅผ ๋งŒ๋“  ํ›„ ๊ทธ ์•ˆ์— ๋„ฃ๊ธฐ -->
{% if latest_question_list %}
    <ul>
    {% for question in latest_question_list %}
        <li><a href="/polls/{{ question.id }}/">{{ question.question_text }}</a></li>
    {% endfor %}
    </ul>
{% else %}
    <p>No polls are available.</p>
{% endif %}
# polls/views.py
from django.http import HttpResponse
from django.template import loader

from .models import Question


def index(request):
    latest_question_list = Question.objects.order_by('-pub_date')[:5]
    #template๋ฅผ ๋กœ๋“œํ•ด์„œ response
    template = loader.get_template('polls/index.html')
    #context๋ฅผ ํ†ตํ•ด latest_question_list์˜ ๋ฐ์ดํ„ฐ๋ฅผ template์—๊ฒŒ ์ „๋‹ฌํ•ด template๊ฐ€ ๋ฐ์ดํ„ฐ๋ฅผ ์‚ฌ์šฉ -> ์œ„์˜ html์ฝ”๋“œ๋ฅผ ๋ณด๋ฉด latest_question_list ํ™•์ธ ๊ฐ€๋Šฅ
    context = {
        'latest_question_list': latest_question_list,
    }
    return HttpResponse(template.render(context, request))
  • render() ์‚ฌ์šฉํ•˜๋ฉด ์ฝ”๋“œ์–‘์„ ์ค„์ผ ์ˆ˜ ์žˆ์Œ. (์ฆ‰ ์œ„์˜ ์ฝ”๋“œ๋ฅผ ์ค„์ผ ์ˆ˜ ์žˆ์Œ.)
from django.shortcuts import render

from .models import Question


def index(request):
    latest_question_list = Question.objects.order_by('-pub_date')[:5]
    context = {'latest_question_list': latest_question_list}
    # render() ํ•จ์ˆ˜์˜ {~:~}๋กœ html ํŒŒ์ผ์—๊ฒŒ ๋„˜๊ฒจ์ฃผ๋˜ dict๋ฅผ context๋ผ๊ณ  ๋ถ€๋ฅธ๋‹ค. 
    return render(request, 'polls/index.html', context)
  • 404 ์—๋Ÿฌ ์ผ์œผํ‚ค๊ธฐ
#polls/views.y
from django.http import Http404
from django.shortcuts import render

from .models import Question
# ...
def detail(request, question_id):
    try:
        question = Question.objects.get(pk=question_id)
    except Question.DoesNotExist: #ํ€˜์Šค์ฒœ์— ๋ฐ์ดํ„ฐ๊ฐ€ ์—†๋Š” ๊ฒฝ์šฐ
        raise Http404("Question does not exist") #๋ฉ”์„ธ์ง€๋œจ๊ฒŒ ํ•˜๊ธฐ
    return render(request, 'polls/detail.html', {'question': question})

get_object_or_404 ์‚ฌ์šฉํ•ด ๋” ์‰ฝ๊ฒŒ ๋งŒ๋“ค๊ธฐ

#polls/views.py
from django.shortcuts import get_object_or_404, render

from .models import Question
# ...
def detail(request, question_id):
    question = get_object_or_404(Question, pk=question_id)
    #list๊ฐ€ return ๋  ์‹œ์—๋Š” get_object_or_404 ๋Œ€์‹  get_list_or_404๋ฅผ ํ™œ์šฉํ•˜๊ธฐ 
    return render(request, 'polls/detail.html', {'question': question})
  • context ๋ณ€์ˆ˜ question์ด ์ฃผ์–ด์กŒ์„๋•Œ
<!-- polls/templates/polls/detail.html-->
<!-- template์— quesiton์„ ๋„˜๊ฒจ ๋ฐ›๊ณ , question์˜ question_text๋ฅผ ์ œ๋ชฉ์œผ๋กœ ๋ณด์—ฌ์คŒ -->

<h1>{{ question.question_text }}</h1>
<ul>
{% for choice in question.choice_set.all %}
    <li>{{ choice.choice_text }}</li>
{% endfor %}
</ul>

<!-- question.choice_set์€ choice๋“ค์ด question์„ ์™ธ๋ž˜ ํ‚ค๋กœ ๊ฐ–๊ณ ์žˆ๋Š” ๋ชจ๋‘๋ฅผ ๊ฐ€์ง€๊ณ  ์™€๋ผ. ์˜ˆ๋ฅผ ๋“ค์–ด what's new๋ผ๋Š” ํ€˜์Šค์ฒœ์ด ์žˆ์œผ๋ฉด what's new์— ๋Œ€ํ•ด ์™ธ๋ž˜ํ‚ค๋ฅผ ๊ฐ–๋Š” ์ดˆ์ด์Šค๋ฅผ ๋‹ค ๊ฐ–๊ณ ์™€๋ผ ๊ทธ๋ฆฌ๊ณ  ๋ฆฌ์ŠคํŠธ๋กœ ๋งŒ๋“ค์–ด์ฃผ๊ธฐ-->
  • ํ…œํ”Œ๋ฆฟ์— ์—ฐ๊ฒฐํ•œ url์ด ๋ณ€๊ฒฝ๋˜๋Š” ๊ฒฝ์šฐ๊ฐ€ ์กด์žฌํ•œ๋‹ค.์ด๋•Œ ํ•˜๋“œ์ฝ”๋”ฉ์„ ํ•ด๋†จ๋‹ค๋ฉด template์— url์ฃผ์†Œ๋„ ๋ณ€๊ฒฝํ•ด์•ผํ•˜๋Š”๋ฐ, url์— ์ด๋ฆ„์„ ๋ช…์‹œํ•ด์„œ url์ด ๋ณ€๊ฒฝ๋˜๋„ ํ…œํ”Œ๋ฆฟ ์ˆ˜์ •์„ ์•ˆํ•ด๋„ ๋˜๊ฒŒ ๋งŒ๋“ ๋‹ค.
<!-- polls/index.html -->
<!-- ํ•˜๋“œ์ฝ”๋”ฉ -->
<li><a href="/polls/{{ question.id }}/">{{ question.question_text }}</a></li>
<!-- polls/index.html -->
<!-- ํŠน์ • ๊ฒฝ๋กœ๋“ค์˜ ์˜์กด์„ฑ์„ ์ œ๊ฑฐ --> 
<li><a href="{% url 'detail' question.id %}">{{ question.question_text }}</a></li>
  • ๊ทธ๋ฆฌ๊ณ  ๋งŒ์•ฝ ์ด๋ฆ„์ด detail์ด๋ผ๋ฉด ๋‹ค๋ฅธ ์•ฑ์—์„œ๋„ detail ์ด๋ฆ„์„ ์‚ฌ์šฉํ•  ์ˆ˜์žˆ๊ธฐ ๋•Œ๋ฌธ์— ์ด๋ฆ„ ๊ณต๊ฐ„์„ ๋งŒ๋“ค์–ด ์ด๋ฆ„์„ ์ง€์–ด์ฃผ๊ณ , ์•ฑ ์ด๋ฆ„์„ ๋ช…์‹œํ•ด์ค€๋‹ค. -->
  • url ์ด๋ฆ„๊ณต๊ฐ„ ์ •ํ•˜๊ธฐ
#polls/urls.py
from django.urls import path

from . import views

app_name = 'polls' # ์ด๋ฆ„ ๋ช…์‹œ ํ›„์—
urlpatterns = [
    path('', views.index, name='index'),
    path('<int:question_id>/', views.detail, name='detail'),
    path('<int:question_id>/results/', views.results, name='results'),
    path('<int:question_id>/vote/', views.vote, name='vote'),
]
<!-- polls/templates/polls/index.html -->
<!-- ์ถ”๊ฐ€ -->
<li><a href="{% url 'polls:detail' question.id %}">{{ question.question_text }}</a></li>
<!-- <a href="/polls/{{ question_id }}/">{{question.question_text}} </a> ํ˜•ํƒœ๋ฅผ ๊ฐ€์ง -->
<!-- ์ด๋ถ€๋ถ„์€ element์—์„œ ํ™•์ธ ๊ฐ€๋Šฅ --> 

- part4

: ํด๋ผ์ด์–ธํŠธ์ธ ์‚ฌ์šฉ์ž๋กœ๋ถ€ํ„ฐ ์„œ๋ฒ„๋กœ ๋ฐ์ดํ„ฐ๋ฅผ ๋ถˆ๋Ÿฌ์˜ค๋Š” ๋ฐฉ๋ฒ•
์‚ฌ์šฉ์ž๊ฐ€ ํšŒ์›๊ฐ€์ž…์ด๋‚˜ ์ฃผ๋ฌธ์„ ํ•˜๋ฉด ์„œ๋ฒ„์ชฝ์œผ๋กœ ์š”์ฒญํ•œ ๋ฐ์ดํ„ฐ๋ฅผ ๋ฐ›์•„์™€์•ผํ•จ.
class ๊ธฐ๋ฐ˜ ํ‘œ๋กœ ๊ตฌํ˜„ํ•˜๋ฉด ์†Œ์Šค์ฝ”๋“œ๊ฐ€ ์ค„์–ด๋“ค์Œ.

<!-- polls/templates/polls/detail.html -->
<!-- form ์š”์†Œ ์ถ”๊ฐ€ -->
<!-- question.choice_set.all๋Š” question์„ ์™ธ๋ž˜ํ‚ค๋กœ ๋ฐ›๋Š” ๋ชจ๋“  ๊ฒƒ๋“ค ๊ฐ€์ ธ์™€ ํ•˜๋‚˜์”ฉ ๋Œ์•„๋ผ --> 

<form action="{% url 'polls:vote' question.id %}" method="post">
{% csrf_token %}
<fieldset>
    <legend><h1>{{ question.question_text }}</h1></legend>
    {% if error_message %}<p><strong>{{ error_message }}</strong></p>{% endif %}
    {% for choice in question.choice_set.all %}
        <input type="radio" name="choice" id="choice{{ forloop.counter }}" value="{{ choice.id }}">
        <label for="choice{{ forloop.counter }}">{{ choice.choice_text }}</label><br>
    {% endfor %}
</fieldset>
<input type="submit" value="Vote">
</form>

<!-- submit์„ ๋ˆ„๋ฅด๋ฉด ํ•ด๋‹น url(= 'polls:vote ) ๋กœ ๋ฐ์ดํ„ฐ(value๊ฐ’)๊ฐ€ ์ „๋‹ฌ(ํ˜ธ์ถœ),๊ทธ๋ฆฌ๊ณ  ํ•ด๋‹น url์— ๊ฑธ๋ ค์žˆ๋Š” views.vote๊ฐ€ ๋ฐ์ดํ„ฐ ์ฒ˜๋ฆฌ -->
<!-- {% csrf_token %}์€ ํ•ดํ‚น๋ฐฉ์ง€๋ฅผ ์œ„ํ•ด ์‚ฝ์ž… -->
  • vote() ํ•จ์ˆ˜ ๋งŒ๋“ค๊ธฐ
#polls/views.py
from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import get_object_or_404, render
from django.urls import reverse

from .models import Choice, Question
# ...

# ํˆฌํ‘œ๋ฅผ ๋งˆ์ณค์„ ๋•Œ ํ•ด๋‹น post์š”์ฒญ์„ ์ฒ˜๋ฆฌํ•ด์ค„ vote ํ•จ์ˆ˜๋ฅผ ์ˆ˜์ •ํ•ด์•ผํ•จ.
def vote(request, question_id): #question_id๋ฅผ ๋„˜๊ฒจ๋ฐ›์Œ 
    question = get_object_or_404(Question, pk=question_id)
    
    try:
        selected_choice = question.choice_set.get(pk=request.POST['choice']) #question์— ๋Œ€ํ•ด ์™ธ๋ž˜ํ‚ค๋ฅผ ๊ฐ–๋Š” ์„ ํƒ์ง€(choice)๋ฅผ ๊ฐ€์ ธ์˜ด(์กฐ๊ฑด์ด ์„ ํƒ์ง€์ค‘์—์„œ  pk๊ฐ’์ด ํ…œํ”Œ๋ฆฟ์—์„œ ๋„˜๊ฒจ๋ฐ›์€ ๊ฐ’)
        # ํ…œํ”Œ๋ฆฟ์—์„œ ํฌ์ŠคํŠธ ๋ฐฉ์‹์œผ๋กœ ํ˜ธ์ถœ์„ ํ–ˆ๊ธฐ ๋–ผ๋ฌธ์—  name์˜ ๋ฐ์ดํ„ฐ๋ฅผ ๊ฐ€์ง€๊ณ ์™€๋ผ(ํ…œํ”Œ๋ฆฟ๋ณด๋ฉด name์ด choice์ธ๊ฑฐ ํ™•์ธ ๊ฐ€๋Šฅ)
        #detail.html์˜ <input type="radio" name="choice" value="{{ choice.id}}"์—์„œ ๋‚ ๋ผ์˜จ ๊ฐ’
        # form์œผ๋กœ ์ œ์ถœ๋œ post request ์ „์ฒด์—์„œ 'choice'๊ฐ€ namedls htmlํƒœ๊ทธ์˜ value๋ฅผ ๊บผ๋‚ด๋Š” ์ฝ”๋“œ
		#request.POST dict๋‚ด์— {'choice':7}๊ณผ ๊ฐ™์ด ๋”•์…”๋„ˆ๋ฆฌ ํ˜•ํƒœ๋กœ ์กด์žฌํ•จ. 
    
    except (KeyError, Choice.DoesNotExist): #์„ ํƒ์ง€๊ฐ€ ์—†์œผ๋ฉด ์˜ˆ์™ธ ๋ฐœ์ƒ
        # Redisplay the question voting form.
        return render(request, 'polls/detail.html', {
            'question': question,
            'error_message': "You didn't select a choice.",
        })
    else: # try๋ฌธ์—์„œ ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•˜์ง€ ์•Š๋Š” ๊ฒฝ์šฐ ๋งˆ์ง€๋ง‰์— ์‹คํ–‰ ๋ฐ์ดํ„ฐ๊ฐ€ ์žˆ๋Š” ๊ฒฝ์šฐ๋„ค๋Š” ์„ ํƒ์ง€์—์„œ +1 ํ•˜๊ณ  ์ €์žฅ
        selected_choice.votes += 1
        selected_choice.save() # ์‚ด์ œ DB ์ €์žฅ
        # Always return an HttpResponseRedirect after successfully dealing
        # with POST data. This prevents data from being posted twice if a
        # user hits the Back button.
        return HttpResponseRedirect(reverse('polls:results', args=(question.id,)))
        
       #post๋กœ view๊ฐ€ ํ˜ธ์ถœ๋œ ๊ฒฝ์šฐ์—๋Š” httpresonpsededirect๋ฅผ ํ•ด์ค€๋‹ค.
       #reverse๋Š” ํ•˜๋“œ์ฝ”๋”ฉ์„ ํ•˜์ง€ ์•Š๊ธฐ์œ„ํ•ด์„œ ์•ฑ๋„ค์ž„,url๋„ค์ž„ ์‚ฌ์šฉํ•จ. 
       # ์ด results url๋กœ ๋‹ค์‹œ  views.py์˜ result ํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœ
  • ํˆฌํ‘œ๋ฅผ ๋งˆ์ณค์„ ๋•Œ ๊ฒฐ๊ณผ๋ฅผ ๋ณด์—ฌ์ค„ result.html ๋งŒ๋“ค๊ธฐ
# polls/views.py

#์œ„์—์„œ ์ด์–ด ํ•จ์ˆ˜๊ฐ€ ํ˜ธ์ถœํ•˜๊ณ  question์„ ์กฐํšŒํ•œ ํ›„ polls/results.htmlํŽ˜์ด์ง€๊ฐ€ ๊ฒฐ๊ณผ ํŽ˜์ด์ง€๋กœ ๋ณด์—ฌ์คŒ
from django.shortcuts import get_object_or_404, render

def results(request, question_id):
    question = get_object_or_404(Question, pk=question_id)
    return render(request, 'polls/results.html', {'question': question})
  #์ด๋•Œ question ๋ฐ์ดํ„ฐ๊ฐ€ ๊ฐ™์ด ๋„˜์–ด๊ฐ€๊ณ , 
<!-- polls/templates/polls/results.html -->
<!-- ๋„˜์–ด๊ฐ„ ๋ฐ์ดํ„ฐ๋Š” question.choice_set.all ์ฆ‰, questino์— ๋Œ€ํ•œ ์„ ํƒ์ง€ ๊ฐ’๋“ค์ด ๋ฐ˜๋ณต๋ฌธ์„ ๋Œ๋ฉด์„œ list๋กœ ๋ฟŒ๋ ค์คŒ. -->
<h1>{{ question.question_text }}</h1>

<ul>
{% for choice in question.choice_set.all %}
    <li>{{ choice.choice_text }} -- {{ choice.votes }} vote{{ choice.votes|pluralize }}</li>
{% endfor %}
</ul>

<a href="{% url 'polls:detail' question.id %}">Vote again?</a>

-โžก๏ธ ์—ฌ๊ธฐ๊นŒ์ง€๊ฐ€ ์‚ฌ์šฉ์ž๋กœ๋ถ€ํ„ฐ ๋ฐ์ดํ„ฐ๋ฅผ ๋ฐ›์•„์˜ค๋Š” ๋ฐฉ๋ฒ•

  • ์ œ๋„ˆ๋ฆญ ๋ทฐ(= ํด๋ž˜์Šค ๊ธฐ๋ฐ˜ ๋ทฐ)๋Š” ์ผ๋ฐ˜์ ์ธ ํŒจํ„ด์„ ์žฅ๊ณ ๊ฐ€ ๋ฏธ๋ฆฌ ๋งŒ๋“ค์–ด๋‘  ์ด๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•ด์„œ
  • urlconfig ์ˆ˜์ •
#polls/urls.py
from django.urls import path

from . import views

app_name = 'polls'
urlpatterns = [
    path('', views.IndexView.as_view(), name='index'), #์žฅ๊ณ ๊ฐ€ ๋ฏธ๋ฆฌ ๋งŒ๋“  as_view๋ฅผ ํ˜ธ์ถœํ•ด์„œ IndexView๋ฅผ ํ˜ธ์ถœํ•จ.
    path('<int:pk>/', views.DetailView.as_view(), name='detail'),
    path('<int:pk>/results/', views.ResultsView.as_view(), name='results'),
    path('<int:question_id>/vote/', views.vote, name='vote'),
]
  • ์ œ๋„ˆ๋ฆญ ๋ทฐ ์ ์šฉํ•˜๊ธฐ
#polls/views.py 
#์ œ๋„ˆ๋ฆญ ๋ทฐ ์‚ฌ์šฉํ•ด์„œ ์ฝ”๋“œ๊ฐ€ ์ค„์–ด๋“ฌ 
from django.http import HttpResponseRedirect
from django.shortcuts import get_object_or_404, render
from django.urls import reverse
from django.views import generic

from .models import Choice, Question


class IndexView(generic.ListView):
    template_name = 'polls/index.html'
    context_object_name = 'latest_question_list'
    #๋งŒ์•ฝ context์— ๋„˜๊ฒจ์ฃผ๋Š” ์ด๋ฆ„์ด ๋ชจ๋ธ ์ด๋ฆ„๊ณผ ๋‹ค๋ฅด๋‹ค๋ฉด context_object_name๋ฅผ ๋‹ค์‹œ ์ •ํ•ด์ฃผ๊ณ  ํ•„์š”ํ•œ ๋ฐ์ดํ„ฐ๋ฅผ ๋ฐ‘์˜ get_querysetํ•จ์ˆ˜๋ฅผ ํ†ตํ•ด ๋‹ค์‹œ ์ž‘์„ฑ

    def get_queryset(self):
        """Return the last five published questions."""
        return Question.objects.order_by('-pub_date')[:5]


class DetailView(generic.DetailView):
    model = Question # ํ…œํ”Œ๋ฆฟ์—์„œ ์‚ฌ์šฉํ•  ๋ฐ์ดํ„ฐ ๋ชจ๋ธ
    template_name = 'polls/detail.html' # ์‚ฌ์šฉํ•  ํ…œํ”Œ๋ฆฟ ์ด๋ฆ„ 


class ResultsView(generic.DetailView):
    model = Question
    template_name = 'polls/results.html'


def vote(request, question_id):
    ... # same as above, no changes needed. 

0๊ฐœ์˜ ๋Œ“๊ธ€