runserverしたい
djangoでrunserverしたいのですが、以下のエラーメッセージでrunserverできません。
エラー全文
error
1$ python manage.py runserver 2Watching for file changes with StatReloader 3Performing system checks... 4 5Exception in thread django-main-thread: 6Traceback (most recent call last): 7 File "/Users/****/Python/myVacation/venv/lib/python3.8/site-packages/django/urls/resolvers.py", line 600, in url_patterns 8 iter(patterns) 9TypeError: 'module' object is not iterable 10 11The above exception was the direct cause of the following exception: 12 13Traceback (most recent call last): 14 File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/threading.py", line 932, in _bootstrap_inner 15 self.run() 16 File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/threading.py", line 870, in run 17 self._target(*self._args, **self._kwargs) 18 File "/Users/****/Python/myVacation/venv/lib/python3.8/site-packages/django/utils/autoreload.py", line 64, in wrapper 19 fn(*args, **kwargs) 20 File "/Users/****/Python/myVacation/venv/lib/python3.8/site-packages/django/core/management/commands/runserver.py", line 118, in inner_run 21 self.check(display_num_errors=True) 22 File "/Users/****/Python/myVacation/venv/lib/python3.8/site-packages/django/core/management/base.py", line 419, in check 23 all_issues = checks.run_checks( 24 File "/Users/****/Python/myVacation/venv/lib/python3.8/site-packages/django/core/checks/registry.py", line 76, in run_checks 25 new_errors = check(app_configs=app_configs, databases=databases) 26 File "/Users/****/Python/myVacation/venv/lib/python3.8/site-packages/django/core/checks/urls.py", line 13, in check_url_config 27 return check_resolver(resolver) 28 File "/Users/****/Python/myVacation/venv/lib/python3.8/site-packages/django/core/checks/urls.py", line 23, in check_resolver 29 return check_method() 30 File "/Users/****/Python/myVacation/venv/lib/python3.8/site-packages/django/urls/resolvers.py", line 412, in check 31 for pattern in self.url_patterns: 32 File "/Users/****/Python/myVacation/venv/lib/python3.8/site-packages/django/utils/functional.py", line 48, in __get__ 33 res = instance.__dict__[self.name] = self.func(instance) 34 File "/Users/****/Python/myVacation/venv/lib/python3.8/site-packages/django/urls/resolvers.py", line 607, in url_patterns 35 raise ImproperlyConfigured(msg.format(name=self.urlconf_name)) from e 36django.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.
環境
macOS : 10.15.4
python : 3.8.1
django : 3.2.5
実際のコード
プロジェクト名:app
アプリケーション名;my_vacation, users
python
1# app.urls.py 2from django.contrib import admin 3from django.urls import path, include 4 5urlpatterns = [ 6 path('admin/', admin.site.urls), 7 path('', include('my_vacation.urls')), 8]
python
1# settings.py 2INSTALLED_APPS = [ 3 'django.contrib.admin', 4 'django.contrib.auth', 5 'django.contrib.contenttypes', 6 'django.contrib.sessions', 7 'django.contrib.messages', 8 'django.contrib.staticfiles', 9 'my_vacation', 10 'users', 11] 12 13ROOT_URLCONF = 'app.urls'
python
1# my_vacation.urls.py 2from django.urls import path 3from . import views 4 5app_name= 'my_vacation' 6urlpatterns = [ 7 path('', views.VacationList.as_view(), name='index'), 8 path('my-vacation/<int:pk>/', views.MyVacation.as_view(), name='my_vacation'), 9 path('detail/<int:pk>/', views.VacationDetail.as_view(), name='detail'), 10 path('edit/<int:pk>/', views.EditVacation.as_view(), name='edit'), 11 path('create/<int:pk>/', views.CreateVacation.as_view(), name='create'), 12 path('delete/<int:pk>/', views.DeleteVacation.as_view(), name='delete'), 13 path('duplicate/<int:pk>/', views.DuplicateVacation.as_view(), name='duplicate'), 14]
python
1# my_vacation.models.py 2from django.db import models 3from django.contrib.auth.models import AbstractUser 4 5from users.models import User 6 7 8class Genre(models.Model): 9 name = models.CharField(max_length=200) 10 11 def __str__(self): 12 return self.name 13 14class MinnanoVacation(models.Model): 15 WITH_LIST = ( 16 ('0', 'ひとりで'), 17 ('1', '恋人と'), 18 ('2', '友達と'), 19 ('3', '家族と'), 20 ('4', '見知らぬ誰かと'), 21 ) 22 23 TIME_REQUIRED_LIST = ( 24 ('0', '1時間以内'), 25 ('1', '2~3時間'), 26 ('2', '半日'), 27 ('3', '1日'), 28 ('4', '1伯以上'), 29 ) 30 31 title = models.CharField('やりたいこと', max_length=200) 32 user = models.ForeignKey(User, on_delete=models.CASCADE) 33 with_who = models.CharField('誰と', max_length=30, choices=WITH_LIST) 34 cost = models.IntegerField('およその金額') 35 time_required = models.CharField('所要時間', max_length=30, choices=TIME_REQUIRED_LIST) 36 genre = models.ManyToManyField(Genre) 37 published = models.BooleanField('公開', default=False) 38 yaritai = models.IntegerField('やってみたい', default=0) 39 copied = models.IntegerField('コピーされた数', default=0) 40 original_id = models.IntegerField(blank=True, null=True) 41 created_at = models.DateTimeField(auto_now_add=True) 42 updated_at = models.DateTimeField(auto_now=True)
python
1# my_vacation.views.py 2from django.shortcuts import render 3from django.urls import reverse, reverse_lazy 4from django.views.generic import ListView, DetailView, UpdateView, CreateView 5from django.db.models import Q 6 7from .models import MinnanoVacation 8from .forms import MinnanoVacationForm 9 10class VacationList(ListView): 11 model = MinnanoVacation 12 template_name = 'index.html' 13 context_object_name = 'vacations' 14 paginate_by = 10 15 16 def get_queryset(self): 17 title = self.request.Get.get('title') 18 with_who = self.request.Get.get('with_who') 19 cost = self.request.Get.get('cost') 20 time_required = self.request.Get.get('time_required') 21 genre = self.request.Get.get('genre') 22 23 queryset = MinnanoVacation.objects.order_by('-created_at') 24 25 if title: 26 queryset = queryset.objects.filter( 27 Q(title__icontains=title) 28 ) 29 elif with_who: 30 queryset = queryset.objects.filter( 31 Q(with_who__icontains=with_who) 32 ) 33 elif cost: 34 queryset = queryset.objects.filter( 35 Q(cost__lte=cost) 36 ) 37 elif time_required: 38 queryset = queryset.objects.filter( 39 Q(time_required__icontains=time_required) 40 ) 41 elif genre: 42 queryset = queryset.objects.filter( 43 Q(genre__icontains=genre) 44 ) 45 46 return queryset 47 48 def post(self, request, *args, **kwargs): 49 yaritai_id = self.request.POST.get('yaritai') 50 vacation = MinnanoVacation.objects.get(id=yaritai_id) 51 vacation.yaritai += 1 52 vacation.save() 53 return reverse('my_vacation:index') 54 55 56class MyVacation(ListView): 57 model = MinnanoVacation 58 context_object_name = 'my_vacations' 59 template_name = 'my-vacation.html' 60 paginate_by = 10 61 62 def get_queryset(self): 63 user = get_object_or_404(MinnanoVacation, user.id==self.kwargs['pk']) 64 queryset = super().get_queryset().filter(user=user) 65 return queryset 66 67class VacationDetail(DetailView): 68 template_name = 'detail.html' 69 model = MinnanoVacation 70 context_object_name = 'vacation' 71 72 def post(self, request, *args, **kwargs): 73 yaritai_id = self.request.POST.get('yaritai') 74 vacation = MinnanoVacation.objects.get(id=yaritai_id) 75 vacation.yaritai += 1 76 vacation.save() 77 return reverse('my_vacation:detail') 78 79 80 81class EditVacation(UpdateView): 82 template_name = 'edit.html' 83 model = MinnanoVacation 84 form_class = MinnanoVacationForm 85 # success_url = reverse('my_vacation:index') # <=こいつが原因 86 success_url = reverse_lazy('my_vacation:index') 87 88 89# 文字数制限のため省略
python
1# manage.py 2#!/usr/bin/env python 3"""Django's command-line utility for administrative tasks.""" 4import os 5import sys 6 7 8def main(): 9 """Run administrative tasks.""" 10 os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'app.settings') 11 try: 12 from django.core.management import execute_from_command_line 13 except ImportError as exc: 14 raise ImportError( 15 "Couldn't import Django. Are you sure it's installed and " 16 "available on your PYTHONPATH environment variable? Did you " 17 "forget to activate a virtual environment?" 18 ) from exc 19 execute_from_command_line(sys.argv) 20 21 22if __name__ == '__main__': 23 main()
$ find . -type d ( -name __pycache__ -o -name migrations -o -name .git ) -prune -false -o -type f ./app/asgi.py ./app/__init__.py ./app/settings.py ./app/urls.py ./app/wsgi.py ./db.sqlite3 ./my_vacation/models.py ./my_vacation/__init__.py ./my_vacation/apps.py ./my_vacation/forms.py ./my_vacation/admin.py ./my_vacation/tests.py ./my_vacation/urls.py ./my_vacation/views.py ./users/models.py ./users/__init__.py ./users/apps.py ./users/admin.py ./users/tests.py ./users/views.py ./templates/duplicate.html ./templates/index.html ./templates/my-vacation.html ./templates/create.html ./templates/edit.html ./templates/detail.html ./templates/delete.html ./manage.py
調べたこと
app.urls.pyの記述ミスでこのエラーが出るみたいなのですが、
どこがおかしいのかがわかりません。
足りない情報等あれば追記いたします。
よろしくお願いいたします。
回答1件
あなたの回答
tips
プレビュー