Created
July 22, 2020 16:06
-
-
Save roosnic1/39d1d3ec740c92b1ef8401444ad31d22 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h1>{{ question.question_text }}</h1> | |
<ul> | |
{% for choice in question.choice_set.all %} | |
<li>{{ choice.choice_text }}</li> | |
{% endfor %} | |
</ul> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% if latest_question_list %} | |
<ul> | |
{% for question in latest_question_list %} | |
<li><a href="{% url 'detail' question.id %}">{{ question.question_text }}</a></li> | |
{% endfor %} | |
</ul> | |
{% else %} | |
<p>No polls are available.</p> | |
{% endif %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.urls import path | |
from . import views | |
urlpatterns = [ | |
# ex: /app/ | |
path('', views.index, name='index'), | |
# ex: /app/5/ | |
path('<int:question_id>/', views.detail, name='detail'), | |
# ex: /app/5/results/ | |
path('<int:question_id>/results/', views.results, name='results'), | |
# ex: /app/5/vote/ | |
path('<int:question_id>/vote/', views.vote, name='vote'), | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.shortcuts import render | |
from django.http import Http404 | |
from .models import Question | |
def index(request): | |
latest_question_list = Question.objects.order_by('-pub_date')[:5] | |
context = {'latest_question_list': latest_question_list} | |
return render(request, 'app/index.html', context) | |
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, 'app/detail.html', {'question': question}) | |
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment