detail view struggle
This commit is contained in:
parent
2b54e70f1b
commit
82b2af8d6b
Binary file not shown.
6
LCAdmin/polls/templates/polls/details.html
Normal file
6
LCAdmin/polls/templates/polls/details.html
Normal file
@ -0,0 +1,6 @@
|
||||
<h1>{{ question.question_text }}</h1>
|
||||
<ul>
|
||||
{% for choice in question.choice_set.all %}
|
||||
<li>{{ choice.choice_text }}</li>
|
||||
{% endfor %}
|
||||
</ul>
|
9
LCAdmin/polls/templates/polls/index.html
Normal file
9
LCAdmin/polls/templates/polls/index.html
Normal file
@ -0,0 +1,9 @@
|
||||
{% if latest_question_list %}
|
||||
<ul>
|
||||
{% for question in latest_question_list %}
|
||||
<li><a href="{% url 'polls:detail' question.id %}">{{ question.question_text }}</a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% else %}
|
||||
<p>No polls are available.</p>
|
||||
{% endif %}
|
@ -1,15 +1,10 @@
|
||||
from django.urls import path
|
||||
|
||||
from . import views
|
||||
|
||||
app_name = 'polls'
|
||||
urlpatterns = [
|
||||
path('', views.index, name='index'),
|
||||
# ex: /polls/
|
||||
path('', views.index, name='index'),
|
||||
# ex: /polls/5/
|
||||
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'),
|
||||
]
|
@ -1,14 +1,18 @@
|
||||
from django.shortcuts import render
|
||||
|
||||
# Create your views here.
|
||||
from django.http import HttpResponse
|
||||
from django.shortcuts import get_object_or_404, render
|
||||
|
||||
from .models import Question
|
||||
|
||||
|
||||
def index(request):
|
||||
return HttpResponse("Hello, world. You're at the polls index.")
|
||||
latest_question_list = Question.objects.order_by('-pub_date')[:5]
|
||||
context = {'latest_question_list': latest_question_list}
|
||||
return render(request, 'polls/index.html', context)
|
||||
|
||||
def detail(request, question_id):
|
||||
return HttpResponse("You're looking at question %s." % question_id)
|
||||
question = get_object_or_404(Question, pk=question_id)
|
||||
return render(request, 'polls/detail.html', {'question': question})
|
||||
|
||||
def results(request, question_id):
|
||||
response = "You're looking at the results of question %s."
|
||||
|
Loading…
Reference in New Issue
Block a user