質問編集履歴

1

丸投げの質問を修正しました。

2018/09/26 04:26

投稿

masafumi_kishid
masafumi_kishid

スコア8

test CHANGED
File without changes
test CHANGED
@@ -1,14 +1,78 @@
1
- **layerと**
1
+ モデルQuestion
2
2
 
3
3
 
4
4
 
5
+ ```ここに言語を入力
6
+
7
+ from django.db import models
8
+
5
- pythonnに取り組んでいます。
9
+ class Question(models.Model):
10
+
11
+ question_text = models.CharField(max_length=200)
12
+
13
+ pub_date = models.DateTimeField('date published')
14
+
15
+ ```
6
16
 
7
17
 
8
18
 
9
- > 引用テキスト
10
19
 
20
+
21
+ viewのコードは
22
+
23
+
24
+
25
+ ```ここに言語を入力
26
+
27
+ from django.http import Http404
28
+
29
+ from django.shortcuts import render
30
+
31
+ from .models import Question
32
+
33
+ # ...
34
+
35
+ def detail(request, question_id):
36
+
37
+ try:
38
+
39
+ question = Question.objects.get(pk=question_id)
40
+
41
+ except Question.DoesNotExist:
42
+
43
+ raise Http404("Question does not exist")
44
+
45
+ return render(request, 'polls/detail.html', {'question': question})
46
+
47
+
48
+
49
+ ```
50
+
51
+ 上記viewをショートカット: get_object_or_404()で書き直したもの
52
+
53
+ ```ここに言語を入力
54
+
55
+ from django.shortcuts import get_object_or_404, render
56
+
57
+
58
+
59
+ from .models import Question
60
+
61
+ # ...
62
+
63
+ def detail(request, question_id):
64
+
65
+ question = get_object_or_404(Question, pk=question_id)
66
+
67
+ return render(request, 'polls/detail.html', {'question': question})
68
+
69
+ ```
70
+
71
+
72
+
73
+ 上記コードの解説文
74
+
11
- 設計思想
75
+ > 設計思想
12
76
 
13
77
 
14
78
 
@@ -16,12 +80,14 @@
16
80
 
17
81
 
18
82
 
19
- 答えは、モデルレイヤとビューレイヤをカップリングしてしまうからです。 Django の最も大きな目標の一つは、ルーズカップリングの維持にあります。いくつかの制御カップリングは、 django.shortcuts モジュールの中にあります。
83
+ 答えは、**モデルレイヤ****ビューレイヤ****カップリング**してしまうからです。 Django の最も大きな目標の一つは、ルーズカップリングの維持にあります。いくつかの制御カップリングは、 django.shortcuts モジュールの中にあります。
20
84
 
21
85
 
22
86
 
87
+
88
+
23
- 引用の説でレイヤーとかカップリング、ルーズカップルとかありますが、全然理解できません。
89
+ **自分なりの解釈**
24
90
 
25
91
 
26
92
 
27
- 噛み砕て説明お願いできますか。
93
+ 設計思想の中の**レイヤ**とはモデルレイヤはmodelの領分、ビューレイヤはviewの領分のことで、上記ショートカットの中でオブジェクトが無時は404送出するとう二つのこと(カップリング)と言う意味よろしいのでしょうか。