回答編集履歴
1
コードを追加
test
CHANGED
@@ -7,3 +7,203 @@
|
|
7
7
|
|
8
8
|
|
9
9
|
> 特定のhtmlを表示する関数1つと、それをルーティングするurls.pyを1つ作る
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
---
|
16
|
+
|
17
|
+
## 2019/08/07追加
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
適当にこんな感じの構成を作りました。
|
22
|
+
|
23
|
+
実行した後、以下に対応した表示ができますが、いかがですか?
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
url|ファイル
|
28
|
+
|
29
|
+
---|---
|
30
|
+
|
31
|
+
localhost:8000/templates/no2 | no2.html
|
32
|
+
|
33
|
+
localhost:8000/templates/index | index.html
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
```text
|
38
|
+
|
39
|
+
├─static_sites
|
40
|
+
|
41
|
+
│ urls.py
|
42
|
+
|
43
|
+
│ views.py
|
44
|
+
|
45
|
+
│
|
46
|
+
|
47
|
+
├─templates
|
48
|
+
|
49
|
+
│ index.html
|
50
|
+
|
51
|
+
│ no2.html
|
52
|
+
|
53
|
+
│
|
54
|
+
|
55
|
+
└─untitled
|
56
|
+
|
57
|
+
urls.py
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
```
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
##### static_sites/urls.py
|
66
|
+
|
67
|
+
```python
|
68
|
+
|
69
|
+
from django.urls import path
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
from . import views
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
urlpatterns = [
|
78
|
+
|
79
|
+
path('', views.index, name='index'),
|
80
|
+
|
81
|
+
path('index', views.show_index, name='show_index'),
|
82
|
+
|
83
|
+
path('no2', views.show_no2, name='show_no2'),
|
84
|
+
|
85
|
+
]
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
```
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
##### static_sites/views.py
|
94
|
+
|
95
|
+
```python
|
96
|
+
|
97
|
+
from django.shortcuts import render
|
98
|
+
|
99
|
+
from django.http import HttpResponse
|
100
|
+
|
101
|
+
from django.shortcuts import render
|
102
|
+
|
103
|
+
# Create your views here.
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
def index(request):
|
110
|
+
|
111
|
+
return HttpResponse("Hello")
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
def show_index(request):
|
118
|
+
|
119
|
+
return render(request, 'index.html')
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
def show_no2(request):
|
126
|
+
|
127
|
+
return render(request, 'no2.html')
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
```
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
##### templates/index.html
|
136
|
+
|
137
|
+
```html
|
138
|
+
|
139
|
+
<!DOCTYPE html>
|
140
|
+
|
141
|
+
<html lang="en">
|
142
|
+
|
143
|
+
<head>
|
144
|
+
|
145
|
+
<meta charset="UTF-8">
|
146
|
+
|
147
|
+
<title>Title</title>
|
148
|
+
|
149
|
+
</head>
|
150
|
+
|
151
|
+
<body>
|
152
|
+
|
153
|
+
index.html
|
154
|
+
|
155
|
+
</body>
|
156
|
+
|
157
|
+
</html>
|
158
|
+
|
159
|
+
```
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
##### templates/no2.html
|
164
|
+
|
165
|
+
```html
|
166
|
+
|
167
|
+
<!DOCTYPE html>
|
168
|
+
|
169
|
+
<html lang="en">
|
170
|
+
|
171
|
+
<head>
|
172
|
+
|
173
|
+
<meta charset="UTF-8">
|
174
|
+
|
175
|
+
<title>Title</title>
|
176
|
+
|
177
|
+
</head>
|
178
|
+
|
179
|
+
<body>
|
180
|
+
|
181
|
+
no2.html
|
182
|
+
|
183
|
+
</body>
|
184
|
+
|
185
|
+
</html>
|
186
|
+
|
187
|
+
```
|
188
|
+
|
189
|
+
|
190
|
+
|
191
|
+
##### untitled/urls.py
|
192
|
+
|
193
|
+
```python
|
194
|
+
|
195
|
+
from django.contrib import admin
|
196
|
+
|
197
|
+
from django.urls import path, include
|
198
|
+
|
199
|
+
|
200
|
+
|
201
|
+
urlpatterns = [
|
202
|
+
|
203
|
+
path('admin/', admin.site.urls),
|
204
|
+
|
205
|
+
path('templates/', include('static_sites.urls')),
|
206
|
+
|
207
|
+
]
|
208
|
+
|
209
|
+
```
|