Python

djangoでrunserverで開発用サーバを起動しようとしたら、「raise ImproperlyConfigured」が出て起動しない場合の確認と対応

tender6admin ・ 約1分

状況

  • python3 manage.py runserverなどで開発用サーバを起動しようとしたら、以下のメッセージが出て起動しませんでした。
Exception in thread django-main-thread:
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/django/urls/resolvers.py", line 591, in url_patterns
    iter(patterns)
TypeError: 'module' object is not iterable
(略)

確認ポイント

  • ソースファイル名とdoes not appear to have any patterns in it.とが出ているので、該当ソースを見る

原因

  • 「urlpatterns」を「urlpetterns」と打ち間違えていた

対応

  • エラーメッセージに出ていた該当ファイルのタイプミスを修正

メッセージの全体

$ python3 manage.py runserver 0.0.0.0:8000
Watching for file changes with StatReloader
Performing system checks...
Exception in thread django-main-thread:Traceback (most recent call last):  File "/usr/local/lib/python3.6/dist-packages/django/urls/resolvers.py", line 591, in url_patterns    iter(patterns)TypeError: 'module' object is not iterable
The above exception was the direct cause of the following exception: