質問編集履歴

4

views.py修正

2021/07/22 07:50

投稿

likelive.geo
likelive.geo

スコア23

test CHANGED
File without changes
test CHANGED
@@ -282,7 +282,7 @@
282
282
 
283
283
  from django.shortcuts import render
284
284
 
285
- from django.urls import reverse
285
+ from django.urls import reverse, reverse_lazy
286
286
 
287
287
  from django.views.generic import ListView, DetailView, UpdateView, CreateView
288
288
 
@@ -410,7 +410,51 @@
410
410
 
411
411
 
412
412
 
413
+ class VacationDetail(DetailView):
414
+
415
+ template_name = 'detail.html'
416
+
417
+ model = MinnanoVacation
418
+
419
+ context_object_name = 'vacation'
420
+
421
+
422
+
423
+ def post(self, request, *args, **kwargs):
424
+
425
+ yaritai_id = self.request.POST.get('yaritai')
426
+
427
+ vacation = MinnanoVacation.objects.get(id=yaritai_id)
428
+
429
+ vacation.yaritai += 1
430
+
431
+ vacation.save()
432
+
433
+ return reverse('my_vacation:detail')
434
+
435
+
436
+
437
+
438
+
439
+
440
+
441
+ class EditVacation(UpdateView):
442
+
443
+ template_name = 'edit.html'
444
+
445
+ model = MinnanoVacation
446
+
447
+ form_class = MinnanoVacationForm
448
+
449
+ # success_url = reverse('my_vacation:index') # <=こいつが原因
450
+
451
+ success_url = reverse_lazy('my_vacation:index')
452
+
453
+
454
+
455
+
456
+
413
- # 文字数制限のため以下省略
457
+ # 文字数制限のため省略
414
458
 
415
459
  ```
416
460
 

3

エラー全文を追記しました。

2021/07/22 07:50

投稿

likelive.geo
likelive.geo

スコア23

test CHANGED
File without changes
test CHANGED
@@ -4,10 +4,80 @@
4
4
 
5
5
 
6
6
 
7
- # エラー
7
+ # エラー全文
8
8
 
9
9
  ```error
10
10
 
11
+ $ python manage.py runserver
12
+
13
+ Watching for file changes with StatReloader
14
+
15
+ Performing system checks...
16
+
17
+
18
+
19
+ Exception in thread django-main-thread:
20
+
21
+ Traceback (most recent call last):
22
+
23
+ File "/Users/****/Python/myVacation/venv/lib/python3.8/site-packages/django/urls/resolvers.py", line 600, in url_patterns
24
+
25
+ iter(patterns)
26
+
27
+ TypeError: 'module' object is not iterable
28
+
29
+
30
+
31
+ The above exception was the direct cause of the following exception:
32
+
33
+
34
+
35
+ Traceback (most recent call last):
36
+
37
+ File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/threading.py", line 932, in _bootstrap_inner
38
+
39
+ self.run()
40
+
41
+ File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/threading.py", line 870, in run
42
+
43
+ self._target(*self._args, **self._kwargs)
44
+
45
+ File "/Users/****/Python/myVacation/venv/lib/python3.8/site-packages/django/utils/autoreload.py", line 64, in wrapper
46
+
47
+ fn(*args, **kwargs)
48
+
49
+ File "/Users/****/Python/myVacation/venv/lib/python3.8/site-packages/django/core/management/commands/runserver.py", line 118, in inner_run
50
+
51
+ self.check(display_num_errors=True)
52
+
53
+ File "/Users/****/Python/myVacation/venv/lib/python3.8/site-packages/django/core/management/base.py", line 419, in check
54
+
55
+ all_issues = checks.run_checks(
56
+
57
+ File "/Users/****/Python/myVacation/venv/lib/python3.8/site-packages/django/core/checks/registry.py", line 76, in run_checks
58
+
59
+ new_errors = check(app_configs=app_configs, databases=databases)
60
+
61
+ File "/Users/****/Python/myVacation/venv/lib/python3.8/site-packages/django/core/checks/urls.py", line 13, in check_url_config
62
+
63
+ return check_resolver(resolver)
64
+
65
+ File "/Users/****/Python/myVacation/venv/lib/python3.8/site-packages/django/core/checks/urls.py", line 23, in check_resolver
66
+
67
+ return check_method()
68
+
69
+ File "/Users/****/Python/myVacation/venv/lib/python3.8/site-packages/django/urls/resolvers.py", line 412, in check
70
+
71
+ for pattern in self.url_patterns:
72
+
73
+ File "/Users/****/Python/myVacation/venv/lib/python3.8/site-packages/django/utils/functional.py", line 48, in __get__
74
+
75
+ res = instance.__dict__[self.name] = self.func(instance)
76
+
77
+ File "/Users/****/Python/myVacation/venv/lib/python3.8/site-packages/django/urls/resolvers.py", line 607, in url_patterns
78
+
79
+ raise ImproperlyConfigured(msg.format(name=self.urlconf_name)) from e
80
+
11
81
  django.core.exceptions.ImproperlyConfigured: The included URLconf 'app.urls' does not appear to have any patterns in it. If you see valid patterns in the file then the issue is probably caused by a circular import.
12
82
 
13
83
  ```
@@ -340,105 +410,7 @@
340
410
 
341
411
 
342
412
 
343
-
344
-
345
- class VacationDetail(DetailView):
346
-
347
- template_name = 'detail.html'
348
-
349
- model = MinnanoVacation
350
-
351
- context_object_name = 'vacation'
352
-
353
-
354
-
355
- def post(self, request, *args, **kwargs):
356
-
357
- yaritai_id = self.request.POST.get('yaritai')
358
-
359
- vacation = MinnanoVacation.objects.get(id=yaritai_id)
360
-
361
- vacation.yaritai += 1
362
-
363
- vacation.save()
413
+ # 文字数制限のため以下省略
364
-
365
- return reverse('my_vacation:detail')
366
-
367
-
368
-
369
-
370
-
371
-
372
-
373
- class EditVacation(UpdateView):
374
-
375
- template_name = 'edit.html'
376
-
377
- model = MinnanoVacation
378
-
379
- form_class = MinnanoVacationForm
380
-
381
- success_url = reverse('vacation:index')
382
-
383
-
384
-
385
-
386
-
387
- class CreateVacation(CreateView):
388
-
389
- template_name = 'create.html'
390
-
391
- model = MinnanoVacation
392
-
393
- form_class = MinnanoVacationForm
394
-
395
- success_url = reverse('vacation:index')
396
-
397
-
398
-
399
-
400
-
401
- class DeleteVacation(DeleteView):
402
-
403
- template_name = 'delete.html'
404
-
405
- model = MinnanoVacation
406
-
407
- success_url = reverse('vacation:index')
408
-
409
-
410
-
411
-
412
-
413
- class DuplicateVacation(DetailView):
414
-
415
- template_name = 'duplicate.html'
416
-
417
- model = MinnanoVacation
418
-
419
- context_object_name = 'vacation'
420
-
421
-
422
-
423
- def post(self, request, *args, **kwargs):
424
-
425
- vacation = MinnanoVacation.objects.get(id=self.kwargs['pk'])
426
-
427
- vacation.copied += 1
428
-
429
- vacation.save()
430
-
431
- vacation.pk = None
432
-
433
- vacation.original_id = self.kwargs['pk']
434
-
435
- vacation.yaritai = 0
436
-
437
- vacation.copied = 0
438
-
439
- vacation.save()
440
-
441
- return reverse('my_vacation:my_vacation')
442
414
 
443
415
  ```
444
416
 

2

manage.pyとfind . -type 〜 の実行結果を追記しました。

2021/07/22 05:27

投稿

likelive.geo
likelive.geo

スコア23

test CHANGED
File without changes
test CHANGED
@@ -1,4 +1,4 @@
1
- # runserveしたい
1
+ # runserverしたい
2
2
 
3
3
  djangoでrunserverしたいのですが、以下のエラーメッセージでrunserverできません。
4
4
 
@@ -442,7 +442,119 @@
442
442
 
443
443
  ```
444
444
 
445
-
445
+ ```python
446
+
447
+ # manage.py
448
+
449
+ #!/usr/bin/env python
450
+
451
+ """Django's command-line utility for administrative tasks."""
452
+
453
+ import os
454
+
455
+ import sys
456
+
457
+
458
+
459
+
460
+
461
+ def main():
462
+
463
+ """Run administrative tasks."""
464
+
465
+ os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'app.settings')
466
+
467
+ try:
468
+
469
+ from django.core.management import execute_from_command_line
470
+
471
+ except ImportError as exc:
472
+
473
+ raise ImportError(
474
+
475
+ "Couldn't import Django. Are you sure it's installed and "
476
+
477
+ "available on your PYTHONPATH environment variable? Did you "
478
+
479
+ "forget to activate a virtual environment?"
480
+
481
+ ) from exc
482
+
483
+ execute_from_command_line(sys.argv)
484
+
485
+
486
+
487
+
488
+
489
+ if __name__ == '__main__':
490
+
491
+ main()
492
+
493
+ ```
494
+
495
+ ```
496
+
497
+ $ find . -type d ( -name __pycache__ -o -name migrations -o -name .git ) -prune -false -o -type f
498
+
499
+
500
+
501
+ ./app/asgi.py
502
+
503
+ ./app/__init__.py
504
+
505
+ ./app/settings.py
506
+
507
+ ./app/urls.py
508
+
509
+ ./app/wsgi.py
510
+
511
+ ./db.sqlite3
512
+
513
+ ./my_vacation/models.py
514
+
515
+ ./my_vacation/__init__.py
516
+
517
+ ./my_vacation/apps.py
518
+
519
+ ./my_vacation/forms.py
520
+
521
+ ./my_vacation/admin.py
522
+
523
+ ./my_vacation/tests.py
524
+
525
+ ./my_vacation/urls.py
526
+
527
+ ./my_vacation/views.py
528
+
529
+ ./users/models.py
530
+
531
+ ./users/__init__.py
532
+
533
+ ./users/apps.py
534
+
535
+ ./users/admin.py
536
+
537
+ ./users/tests.py
538
+
539
+ ./users/views.py
540
+
541
+ ./templates/duplicate.html
542
+
543
+ ./templates/index.html
544
+
545
+ ./templates/my-vacation.html
546
+
547
+ ./templates/create.html
548
+
549
+ ./templates/edit.html
550
+
551
+ ./templates/detail.html
552
+
553
+ ./templates/delete.html
554
+
555
+ ./manage.py
556
+
557
+ ```
446
558
 
447
559
 
448
560
 

1

models.pyとviews.pyを追記しました。

2021/07/21 22:44

投稿

likelive.geo
likelive.geo

スコア23

test CHANGED
File without changes
test CHANGED
@@ -118,6 +118,334 @@
118
118
 
119
119
 
120
120
 
121
+ ```python
122
+
123
+ # my_vacation.models.py
124
+
125
+ from django.db import models
126
+
127
+ from django.contrib.auth.models import AbstractUser
128
+
129
+
130
+
131
+ from users.models import User
132
+
133
+
134
+
135
+
136
+
137
+ class Genre(models.Model):
138
+
139
+ name = models.CharField(max_length=200)
140
+
141
+
142
+
143
+ def __str__(self):
144
+
145
+ return self.name
146
+
147
+
148
+
149
+ class MinnanoVacation(models.Model):
150
+
151
+ WITH_LIST = (
152
+
153
+ ('0', 'ひとりで'),
154
+
155
+ ('1', '恋人と'),
156
+
157
+ ('2', '友達と'),
158
+
159
+ ('3', '家族と'),
160
+
161
+ ('4', '見知らぬ誰かと'),
162
+
163
+ )
164
+
165
+
166
+
167
+ TIME_REQUIRED_LIST = (
168
+
169
+ ('0', '1時間以内'),
170
+
171
+ ('1', '2~3時間'),
172
+
173
+ ('2', '半日'),
174
+
175
+ ('3', '1日'),
176
+
177
+ ('4', '1伯以上'),
178
+
179
+ )
180
+
181
+
182
+
183
+ title = models.CharField('やりたいこと', max_length=200)
184
+
185
+ user = models.ForeignKey(User, on_delete=models.CASCADE)
186
+
187
+ with_who = models.CharField('誰と', max_length=30, choices=WITH_LIST)
188
+
189
+ cost = models.IntegerField('およその金額')
190
+
191
+ time_required = models.CharField('所要時間', max_length=30, choices=TIME_REQUIRED_LIST)
192
+
193
+ genre = models.ManyToManyField(Genre)
194
+
195
+ published = models.BooleanField('公開', default=False)
196
+
197
+ yaritai = models.IntegerField('やってみたい', default=0)
198
+
199
+ copied = models.IntegerField('コピーされた数', default=0)
200
+
201
+ original_id = models.IntegerField(blank=True, null=True)
202
+
203
+ created_at = models.DateTimeField(auto_now_add=True)
204
+
205
+ updated_at = models.DateTimeField(auto_now=True)
206
+
207
+ ```
208
+
209
+ ```python
210
+
211
+ # my_vacation.views.py
212
+
213
+ from django.shortcuts import render
214
+
215
+ from django.urls import reverse
216
+
217
+ from django.views.generic import ListView, DetailView, UpdateView, CreateView
218
+
219
+ from django.db.models import Q
220
+
221
+
222
+
223
+ from .models import MinnanoVacation
224
+
225
+ from .forms import MinnanoVacationForm
226
+
227
+
228
+
229
+ class VacationList(ListView):
230
+
231
+ model = MinnanoVacation
232
+
233
+ template_name = 'index.html'
234
+
235
+ context_object_name = 'vacations'
236
+
237
+ paginate_by = 10
238
+
239
+
240
+
241
+ def get_queryset(self):
242
+
243
+ title = self.request.Get.get('title')
244
+
245
+ with_who = self.request.Get.get('with_who')
246
+
247
+ cost = self.request.Get.get('cost')
248
+
249
+ time_required = self.request.Get.get('time_required')
250
+
251
+ genre = self.request.Get.get('genre')
252
+
253
+
254
+
255
+ queryset = MinnanoVacation.objects.order_by('-created_at')
256
+
257
+
258
+
259
+ if title:
260
+
261
+ queryset = queryset.objects.filter(
262
+
263
+ Q(title__icontains=title)
264
+
265
+ )
266
+
267
+ elif with_who:
268
+
269
+ queryset = queryset.objects.filter(
270
+
271
+ Q(with_who__icontains=with_who)
272
+
273
+ )
274
+
275
+ elif cost:
276
+
277
+ queryset = queryset.objects.filter(
278
+
279
+ Q(cost__lte=cost)
280
+
281
+ )
282
+
283
+ elif time_required:
284
+
285
+ queryset = queryset.objects.filter(
286
+
287
+ Q(time_required__icontains=time_required)
288
+
289
+ )
290
+
291
+ elif genre:
292
+
293
+ queryset = queryset.objects.filter(
294
+
295
+ Q(genre__icontains=genre)
296
+
297
+ )
298
+
299
+
300
+
301
+ return queryset
302
+
303
+
304
+
305
+ def post(self, request, *args, **kwargs):
306
+
307
+ yaritai_id = self.request.POST.get('yaritai')
308
+
309
+ vacation = MinnanoVacation.objects.get(id=yaritai_id)
310
+
311
+ vacation.yaritai += 1
312
+
313
+ vacation.save()
314
+
315
+ return reverse('my_vacation:index')
316
+
317
+
318
+
319
+
320
+
321
+ class MyVacation(ListView):
322
+
323
+ model = MinnanoVacation
324
+
325
+ context_object_name = 'my_vacations'
326
+
327
+ template_name = 'my-vacation.html'
328
+
329
+ paginate_by = 10
330
+
331
+
332
+
333
+ def get_queryset(self):
334
+
335
+ user = get_object_or_404(MinnanoVacation, user.id==self.kwargs['pk'])
336
+
337
+ queryset = super().get_queryset().filter(user=user)
338
+
339
+ return queryset
340
+
341
+
342
+
343
+
344
+
345
+ class VacationDetail(DetailView):
346
+
347
+ template_name = 'detail.html'
348
+
349
+ model = MinnanoVacation
350
+
351
+ context_object_name = 'vacation'
352
+
353
+
354
+
355
+ def post(self, request, *args, **kwargs):
356
+
357
+ yaritai_id = self.request.POST.get('yaritai')
358
+
359
+ vacation = MinnanoVacation.objects.get(id=yaritai_id)
360
+
361
+ vacation.yaritai += 1
362
+
363
+ vacation.save()
364
+
365
+ return reverse('my_vacation:detail')
366
+
367
+
368
+
369
+
370
+
371
+
372
+
373
+ class EditVacation(UpdateView):
374
+
375
+ template_name = 'edit.html'
376
+
377
+ model = MinnanoVacation
378
+
379
+ form_class = MinnanoVacationForm
380
+
381
+ success_url = reverse('vacation:index')
382
+
383
+
384
+
385
+
386
+
387
+ class CreateVacation(CreateView):
388
+
389
+ template_name = 'create.html'
390
+
391
+ model = MinnanoVacation
392
+
393
+ form_class = MinnanoVacationForm
394
+
395
+ success_url = reverse('vacation:index')
396
+
397
+
398
+
399
+
400
+
401
+ class DeleteVacation(DeleteView):
402
+
403
+ template_name = 'delete.html'
404
+
405
+ model = MinnanoVacation
406
+
407
+ success_url = reverse('vacation:index')
408
+
409
+
410
+
411
+
412
+
413
+ class DuplicateVacation(DetailView):
414
+
415
+ template_name = 'duplicate.html'
416
+
417
+ model = MinnanoVacation
418
+
419
+ context_object_name = 'vacation'
420
+
421
+
422
+
423
+ def post(self, request, *args, **kwargs):
424
+
425
+ vacation = MinnanoVacation.objects.get(id=self.kwargs['pk'])
426
+
427
+ vacation.copied += 1
428
+
429
+ vacation.save()
430
+
431
+ vacation.pk = None
432
+
433
+ vacation.original_id = self.kwargs['pk']
434
+
435
+ vacation.yaritai = 0
436
+
437
+ vacation.copied = 0
438
+
439
+ vacation.save()
440
+
441
+ return reverse('my_vacation:my_vacation')
442
+
443
+ ```
444
+
445
+
446
+
447
+
448
+
121
449
  # 調べたこと
122
450
 
123
451
  app.urls.pyの記述ミスでこのエラーが出るみたいなのですが、