Django” ModuleNotFoundError: No module named ‘example/’ “の解決

DjangoTutorialModuleNotFoundError Webアプリ開発日記

Djangoの公式チュートリアルに沿って、お勉強を進めていたのですが、

Hello, world.でつまづいた!

Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x7f9178a25ef0>
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/django/utils/autoreload.py", line 225, in wrapper
fn(*args, **kwargs)
File "/usr/local/lib/python3.7/site-packages/django/core/management/commands/runserver.py", line 117, in inner_run
self.check(display_num_errors=True)
File "/usr/local/lib/python3.7/site-packages/django/core/management/base.py", line 379, in check
include_deployment_checks=include_deployment_checks,
File "/usr/local/lib/python3.7/site-packages/django/core/management/base.py", line 366, in _run_checks
return checks.run_checks(**kwargs)
File "/usr/local/lib/python3.7/site-packages/django/core/checks/registry.py", line 71, in run_checks
new_errors = check(app_configs=app_configs)
File "/usr/local/lib/python3.7/site-packages/django/core/checks/urls.py", line 13, in check_url_config
return check_resolver(resolver)
File "/usr/local/lib/python3.7/site-packages/django/core/checks/urls.py", line 23, in check_resolver
return check_method()
File "/usr/local/lib/python3.7/site-packages/django/urls/resolvers.py", line 396, in check
for pattern in self.url_patterns:
File "/usr/local/lib/python3.7/site-packages/django/utils/functional.py", line 37, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/usr/local/lib/python3.7/site-packages/django/urls/resolvers.py", line 533, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/usr/local/lib/python3.7/site-packages/django/utils/functional.py", line 37, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/usr/local/lib/python3.7/site-packages/django/urls/resolvers.py", line 526, in urlconf_module
return import_module(self.urlconf_name)
File "/usr/local/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/code/Clearer/urls.py", line 20, in <module>
include('coaching/', include('coaching.urls')),
File "/usr/local/lib/python3.7/site-packages/django/urls/conf.py", line 34, in include
urlconf_module = import_module(urlconf_module)
File "/usr/local/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 965, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'coaching/'

何ですって。
とりあえず
ModuleNotFoundError

らしいので調べると

"No module named polls.urls" error from djangolearning

それっぽいのがヒット。
だが、バシッと解決策は提示しておらず、これを頼りにどうにかとモデルを書いたりとかしましたが、うまくいきませんでした。

結論としては、

アプリケーションディレクトリのurls.pyの文法ミス!

urlpatterns = [
path('', views.index, name='index'),
]

↑のように書かなければいけないところを、

urlpatterns = [
path('', views.index, name='index')
]

と書いていました。”,”を書いていなかった……。

気をつけろ、私。

コメント

タイトルとURLをコピーしました