質問編集履歴
1
該当箇所の列挙
test
CHANGED
File without changes
|
test
CHANGED
@@ -82,9 +82,127 @@
|
|
82
82
|
|
83
83
|
### 該当のソースコード
|
84
84
|
|
85
|
-
該当する箇所が分からない
|
85
|
+
該当する箇所が分からないが、該当しそうな箇所を記述しようと思います
|
86
|
+
|
86
|
-
|
87
|
+
```polls/urls.py
|
88
|
+
|
89
|
+
from django.urls import path
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
from . import views
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
app_name = 'polls'
|
98
|
+
|
99
|
+
|
100
|
+
|
87
|
-
|
101
|
+
urlpatterns = [
|
102
|
+
|
103
|
+
#path('', views.index, name='index'),
|
104
|
+
|
105
|
+
#path('<int:question_id>/', views.detail, name='detail'),
|
106
|
+
|
107
|
+
#path('<int:question_id>/result', views.results, name='result'),
|
108
|
+
|
109
|
+
path('<int:question_id>/vote/', views.vote, name='vote'),
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
path('', views.IndexView, name='index'),
|
114
|
+
|
115
|
+
path('<int:pk>/', views.DetailView.as_view(), name='detail'),
|
116
|
+
|
117
|
+
path('<int:pk>/results/', views.ResultsView.as_view(), name='results'),
|
118
|
+
|
119
|
+
]
|
120
|
+
|
121
|
+
```
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
```polls/views.py
|
126
|
+
|
127
|
+
def vote(request, question_id):
|
128
|
+
|
129
|
+
return HttpResponse("You're voting on question %s." % question_id)
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
class IndexView(generic.ListView):
|
134
|
+
|
135
|
+
template_name = 'polls/index.html'
|
136
|
+
|
137
|
+
context_object_name = 'latest_question_list'
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
def get_queryset(self):
|
142
|
+
|
143
|
+
#return Question.objects.order_by('-pub_date')[:5]
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
return Question.objects.filter(
|
148
|
+
|
149
|
+
pub_date__lte = timezone.now()
|
150
|
+
|
151
|
+
).order_by('-pub_date')[:5]
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
class DetailView(generic.DetailView):
|
156
|
+
|
157
|
+
model = Question
|
158
|
+
|
159
|
+
template_name = 'polls/detail.html'
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
def get_queryset(self):
|
164
|
+
|
165
|
+
return Question.objects.filter(pub_date__lte=timezone.now())
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
class ResultsView(generic.DetailView):
|
170
|
+
|
171
|
+
model = Question
|
172
|
+
|
173
|
+
template_name = 'polls/results.html'
|
174
|
+
|
175
|
+
```
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
```polls/templates/polls/index.html
|
180
|
+
|
181
|
+
{% load static %}
|
182
|
+
|
183
|
+
|
184
|
+
|
185
|
+
<link rel="stylesheet" type="text/css" href="{% static 'polls/style.css' %}">
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
{% if latest_question_list %}
|
190
|
+
|
191
|
+
<ul>
|
192
|
+
|
193
|
+
{% for question in latest_question_list %}
|
194
|
+
|
195
|
+
<li><a href="{% url 'polls:detail' question_id %}">{{ question.question_text }}</a>></li>
|
196
|
+
|
197
|
+
{% endfor %}
|
198
|
+
|
199
|
+
</ul>
|
200
|
+
|
201
|
+
{% else %}
|
202
|
+
|
203
|
+
<p>No polls are available</p>
|
204
|
+
|
205
|
+
{% endif %}
|
88
206
|
|
89
207
|
```
|
90
208
|
|