diadia

興味があることをやってみる。自分のメモを残しておきます。

If you see valid patterns in the file then the issue is probably caused by a circular import.

エラー内容

The included URLconf '<module 'apps.urls' from 'hoge/apps/urls.py'>' 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.

文章の意味は、apps/urls.pyにurlのパターンが存在しないからエラーが出ている。ちゃんとurlのパターンが書かれている場合にはcircular importが原因の可能性がある。

エラーのあったコード

urlspattern = [
    path(
	'confirm/', 
	TemplateView.as_view(template_name="apps/confirm.html"),
	name="confirm"
	),]

 

今回の対処

今回はurls.pyのurlパターンを書けていなかったからエラーになってしまった。urlspatternではなくてurlpatternsが正しい書き方だった。

urlpatterns = [
    path(
	'confirm/', 
	TemplateView.as_view(template_name="apps/confirm.html"),
	name="confirm"
	),]

 

過去のエラーの場合

 django-admin startproject hogehoge.urlsにおいてpath以下の書き方が間違ったときも同じエラーが出てしまった。通常、include()を使う場合は以下のように書く。

from django.urls import path, include

urlpatterns = [
    path("index", include("app.urls")),
    ]

しかしながら以下のように書いてしまい、同じエラーを発生させてしまった。

from django.urls import path, include

urlpatterns = [
    path("index", include("app")),
    ]

apps.urlsまで書くのが正しい書き方です。