Django의 url 설정 시 오류
- Django에서 새로운 앱을 만들고, 프로젝트 urls.py에서 새로운 앱의 url을 include 형식으로 연결하는 과정에서 오류가 발생했다.
urlpatterns = [
path('admin/', admin.site.urls),
path('accounts/' , include('accountapp.urls')),
path('profiles/', include('profileapp.urls')),
path('articles/',include('articleapp.urls')),
path('comments/',include('commentapp.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.
Exception in thread django-main-thread:
Traceback (most recent call last):
File "C:\Users\SAMSUNG\Desktop\Pinterest\venv\lib\site-packages\django\urls\resolvers.py", line 600, in url_patterns
iter(patterns)
TypeError: 'module' object is not iterable
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\SAMSUNG\AppData\Local\Programs\Python\Python39\lib\threading.py", line 973, in _bootstrap_inner
self.run()
File "C:\Users\SAMSUNG\AppData\Local\Programs\Python\Python39\lib\threading.py", line 910, in run
self._target(*self._args, **self._kwargs)
File "C:\Users\SAMSUNG\Desktop\Pinterest\venv\lib\site-packages\django\utils\autoreload.py", line 64, in wrapper
fn(*args, **kwargs)
File "C:\Users\SAMSUNG\Desktop\Pinterest\venv\lib\site-packages\django\core\management\commands\runserver.py", line 118, in inner_run
self.check(display_num_errors=True)
File "C:\Users\SAMSUNG\Desktop\Pinterest\venv\lib\site-packages\django\core\management\base.py", line 419, in check
all_issues = checks.run_checks(
File "C:\Users\SAMSUNG\Desktop\Pinterest\venv\lib\site-packages\django\core\checks\registry.py", line 76, in run_checks
new_errors = check(app_configs=app_configs, databases=databases)
File "C:\Users\SAMSUNG\Desktop\Pinterest\venv\lib\site-packages\django\core\checks\urls.py", line 13, in check_url_config
return check_resolver(resolver)
File "C:\Users\SAMSUNG\Desktop\Pinterest\venv\lib\site-packages\django\core\checks\urls.py", line 23, in check_resolver
return check_method()
File "C:\Users\SAMSUNG\Desktop\Pinterest\venv\lib\site-packages\django\urls\resolvers.py", line 413, in check
messages.extend(check_resolver(pattern))
File "C:\Users\SAMSUNG\Desktop\Pinterest\venv\lib\site-packages\django\core\checks\urls.py", line 23, in check_resolver
return check_method()
File "C:\Users\SAMSUNG\Desktop\Pinterest\venv\lib\site-packages\django\urls\resolvers.py", line 412, in check
for pattern in self.url_patterns:
File "C:\Users\SAMSUNG\Desktop\Pinterest\venv\lib\site-packages\django\utils\functional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Users\SAMSUNG\Desktop\Pinterest\venv\lib\site-packages\django\urls\resolvers.py", line 607, in url_patterns
raise ImproperlyConfigured(msg.format(name=self.urlconf_name)) from e
django.core.exceptions.ImproperlyConfigured:
The included URLconf '<module 'commentapp.urls' from 'C:\\Users\\SAMSUNG\\Desktop\\Pinterest\\commentapp\\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.
해결 방법
- 오류의 이유는 간단했다. 새로운, 앱에서 urls.py를 만들어줬지만 urlpatterns를 입력해놓지 않아서였다.
- 따라서, 해당 앱에 urlpatterns 만 정의해주면 해결할 수 있다.
urlpatterns = [
]