質問編集履歴

2

書きミスを直しました。

2021/11/05 15:55

投稿

rike
rike

スコア0

test CHANGED
File without changes
test CHANGED
@@ -30,7 +30,7 @@
30
30
 
31
31
  ### 該当のソースコード
32
32
 
33
-
33
+ post_list.html
34
34
 
35
35
  ```post_list.html
36
36
 
@@ -58,6 +58,8 @@
58
58
 
59
59
  ```
60
60
 
61
+ views.py
62
+
61
63
  ```views.py
62
64
 
63
65
  from django.shortcuts import render, get_object_or_404
@@ -102,6 +104,8 @@
102
104
 
103
105
  ```
104
106
 
107
+ setting.py
108
+
105
109
  ```setting.py
106
110
 
107
111
  """

1

ソースコードを追加しました。

2021/11/05 15:55

投稿

rike
rike

スコア0

test CHANGED
File without changes
test CHANGED
@@ -32,7 +32,7 @@
32
32
 
33
33
 
34
34
 
35
- ```ここに言語名を入力
35
+ ```post_list.html
36
36
 
37
37
  <div>
38
38
 
@@ -58,7 +58,299 @@
58
58
 
59
59
  ```
60
60
 
61
-
61
+ ```views.py
62
+
63
+ from django.shortcuts import render, get_object_or_404
64
+
65
+ from django.shortcuts import render
66
+
67
+ from django.utils import timezone
68
+
69
+ from .models import Post
70
+
71
+ from django.views.generic import ListView
72
+
73
+
74
+
75
+ class PostListView(ListView):
76
+
77
+ model = Post
78
+
79
+
80
+
81
+ def get_queryset(self):
82
+
83
+ return Post.objects.filter(published_date__lte=timezone.now()).order_by('-published_date')
84
+
85
+
86
+
87
+ def post_list(request):
88
+
89
+ posts = Post.objects.filter(published_date__lte=timezone.now()).order_by('published_date')
90
+
91
+ return render(request, 'blog/post_list.html', {'posts': posts})
92
+
93
+
94
+
95
+ def post_detail(request, pk):
96
+
97
+ post = get_object_or_404(Post, pk=pk)
98
+
99
+ return render(request, 'blog/post_detail.html', {'post': post})
100
+
101
+
102
+
103
+ ```
104
+
105
+ ```setting.py
106
+
107
+ """
108
+
109
+ Django settings for mysite project.
110
+
111
+
112
+
113
+ Generated by 'django-admin startproject' using Django 2.2.24.
114
+
115
+
116
+
117
+ For more information on this file, see
118
+
119
+ https://docs.djangoproject.com/en/2.2/topics/settings/
120
+
121
+
122
+
123
+ For the full list of settings and their values, see
124
+
125
+ https://docs.djangoproject.com/en/2.2/ref/settings/
126
+
127
+ """
128
+
129
+
130
+
131
+ import os
132
+
133
+
134
+
135
+ # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
136
+
137
+ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
138
+
139
+
140
+
141
+
142
+
143
+ # Quick-start development settings - unsuitable for production
144
+
145
+ # See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/
146
+
147
+
148
+
149
+ # SECURITY WARNING: keep the secret key used in production secret!
150
+
151
+ SECRET_KEY = '8jkypoy2d4*t!d3c_xg4(&vh!@s-)qjn4)rgj7sc5*940bdqt2'
152
+
153
+
154
+
155
+ # SECURITY WARNING: don't run with debug turned on in production!
156
+
157
+ DEBUG = True
158
+
159
+
160
+
161
+ ALLOWED_HOSTS = ['127.0.0.1', '.pythonanywhere.com']
162
+
163
+
164
+
165
+
166
+
167
+ # Application definition
168
+
169
+
170
+
171
+ INSTALLED_APPS = [
172
+
173
+ 'django.contrib.admin',
174
+
175
+ 'django.contrib.auth',
176
+
177
+ 'django.contrib.contenttypes',
178
+
179
+ 'django.contrib.sessions',
180
+
181
+ 'django.contrib.messages',
182
+
183
+ 'django.contrib.staticfiles',
184
+
185
+ 'blog.apps.BlogConfig',
186
+
187
+ ]
188
+
189
+
190
+
191
+ MIDDLEWARE = [
192
+
193
+ 'django.middleware.security.SecurityMiddleware',
194
+
195
+ 'django.contrib.sessions.middleware.SessionMiddleware',
196
+
197
+ 'django.middleware.common.CommonMiddleware',
198
+
199
+ 'django.middleware.csrf.CsrfViewMiddleware',
200
+
201
+ 'django.contrib.auth.middleware.AuthenticationMiddleware',
202
+
203
+ 'django.contrib.messages.middleware.MessageMiddleware',
204
+
205
+ 'django.middleware.clickjacking.XFrameOptionsMiddleware',
206
+
207
+ ]
208
+
209
+
210
+
211
+ ROOT_URLCONF = 'mysite.urls'
212
+
213
+
214
+
215
+ TEMPLATES = [
216
+
217
+ {
218
+
219
+ 'BACKEND': 'django.template.backends.django.DjangoTemplates',
220
+
221
+ 'DIRS': [],
222
+
223
+ 'APP_DIRS': True,
224
+
225
+ 'OPTIONS': {
226
+
227
+ 'context_processors': [
228
+
229
+ 'django.template.context_processors.debug',
230
+
231
+ 'django.template.context_processors.request',
232
+
233
+ 'django.contrib.auth.context_processors.auth',
234
+
235
+ 'django.contrib.messages.context_processors.messages',
236
+
237
+ ],
238
+
239
+ },
240
+
241
+ },
242
+
243
+ ]
244
+
245
+
246
+
247
+ WSGI_APPLICATION = 'mysite.wsgi.application'
248
+
249
+
250
+
251
+
252
+
253
+ # Database
254
+
255
+ # https://docs.djangoproject.com/en/2.2/ref/settings/#databases
256
+
257
+
258
+
259
+ DATABASES = {
260
+
261
+ 'default': {
262
+
263
+ 'ENGINE': 'django.db.backends.sqlite3',
264
+
265
+ 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
266
+
267
+ }
268
+
269
+ }
270
+
271
+
272
+
273
+
274
+
275
+ # Password validation
276
+
277
+ # https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators
278
+
279
+
280
+
281
+ AUTH_PASSWORD_VALIDATORS = [
282
+
283
+ {
284
+
285
+ 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
286
+
287
+ },
288
+
289
+ {
290
+
291
+ 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
292
+
293
+ },
294
+
295
+ {
296
+
297
+ 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
298
+
299
+ },
300
+
301
+ {
302
+
303
+ 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
304
+
305
+ },
306
+
307
+ ]
308
+
309
+
310
+
311
+
312
+
313
+ # Internationalization
314
+
315
+ # https://docs.djangoproject.com/en/2.2/topics/i18n/
316
+
317
+
318
+
319
+ LANGUAGE_CODE = 'ja'
320
+
321
+
322
+
323
+ TIME_ZONE = 'Asia/Tokyo'
324
+
325
+
326
+
327
+ USE_I18N = True
328
+
329
+
330
+
331
+ USE_L10N = True
332
+
333
+
334
+
335
+ USE_TZ = True
336
+
337
+
338
+
339
+
340
+
341
+ # Static files (CSS, JavaScript, Images)
342
+
343
+ # https://docs.djangoproject.com/en/2.2/howto/static-files/
344
+
345
+
346
+
347
+ STATIC_URL = '/static/'
348
+
349
+ STATIC_ROOT = os.path.join(BASE_DIR, 'static')
350
+
351
+
352
+
353
+ ```
62
354
 
63
355
  ### 試したこと
64
356