質問編集履歴

1

views.pyを追加しました

2021/01/20 06:21

投稿

Ma_sa
Ma_sa

スコア14

test CHANGED
File without changes
test CHANGED
@@ -58,6 +58,10 @@
58
58
 
59
59
  |- manage.py
60
60
 
61
+ |- nba/ (appの名前)
62
+
63
+ | └ views.py
64
+
61
65
  |- templates/
62
66
 
63
67
  | └ .html
@@ -130,7 +134,7 @@
130
134
 
131
135
 
132
136
 
133
- - .html(templatesの中)
137
+ - stats.html(templatesの中)
134
138
 
135
139
 
136
140
 
@@ -256,6 +260,52 @@
256
260
 
257
261
 
258
262
 
263
+ - views.py
264
+
265
+ ```python
266
+
267
+ from django.shortcuts import render
268
+
269
+ from django.views.generic import ListView,TemplateView
270
+
271
+ from .models import PlayerModel
272
+
273
+ from django.urls import reverse_lazy
274
+
275
+
276
+
277
+ # Create your views here
278
+
279
+
280
+
281
+ class PlayerList(ListView):
282
+
283
+ template_name = "list.html"
284
+
285
+ model = PlayerModel
286
+
287
+
288
+
289
+ class ShowStats(TemplateView):
290
+
291
+ template_name = "stats.html"
292
+
293
+ model = PlayerModel
294
+
295
+
296
+
297
+ def get_context_data(self, **kwargs):
298
+
299
+ context = super().get_context_data(**kwargs)
300
+
301
+ context['object'] = PlayerModel.objects.get(pk=self.kwargs.get('pk'))
302
+
303
+ return context
304
+
305
+ ```
306
+
307
+
308
+
259
309
 
260
310
 
261
311