Introduction
This article is showing about how to solve an error message in running Django-based application. The execution actually triggering the error message as it exist in the title of this article. The full complete error exist as follows :
django.core.exceptions.ImproperlyConfigured: The included URLconf '<module 'app.urls' from 'C:\\programming\\python\\myproject\\app\\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.
(env) C:\programming\python\project\myproject>python manage.py runserver Watching for file changes with StatReloader Performing system checks... Exception in thread django-main-thread: Traceback (most recent call last): File "C:\programming\python\project\env\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:\Python38\lib\threading.py", line 932, in _bootstrap_inner self.run() File "C:\Python38\lib\threading.py", line 870, in run self._target(*self._args, **self._kwargs) File "C:\programming\python\project\env\lib\site-packages\django\utils\autoreload.py", line 64, in wrapper fn(*args, **kwargs) File "C:\programming\python\project\env\lib\site-packages\django\core\management\commands\runserver.py", line 118, in inner_run self.check(display_num_errors=True) File "C:\programming\python\project\env\lib\site-packages\django\core\management\base.py", line 419, in check all_issues = checks.run_checks( File "C:\programming\python\project\env\lib\site-packages\django\core\checks\registry.py", line 76, in run_checks new_errors = check(app_configs=app_configs, databases=databases) File "C:\programming\python\project\env\lib\site-packages\django\core\checks\urls.py", line 13, in check_url_config return check_resolver(resolver) File "C:\programming\python\project\env\lib\site-packages\django\core\checks\urls.py", line 23, in check_resolver return check_method() File "C:\programming\python\project\env\lib\site-packages\django\urls\resolvers.py", line 413, in check messages.extend(check_resolver(pattern)) File "C:\programming\python\project\env\lib\site-packages\django\core\checks\urls.py", line 23, in check_resolver return check_method() File "C:\programming\python\project\env\lib\site-packages\django\urls\resolvers.py", line 412, in check for pattern in self.url_patterns: File "C:\programming\python\project\env\lib\site-packages\django\utils\functional.py", line 48, in __get__ res = instance.__dict__[self.name] = self.func(instance) File "C:\programming\python\project\env\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 'app.urls' from 'C:\\programming\\python\\project\\myproject\\app\\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.
Solution
One of the cause which is triggering the error message is because of the common and simple mistake for those who start learning python syntakses and Django style configuration. According to the information above, there is something that causing an error in ‘urls.py’ file. The following is the original content of the ‘urls.py’ in the app folder causing the error :
from django.contrib import admin from django.urls import path, re_path, include from app import views path('', views.index, name='home'), re_path(r'^.*\.*', views.pages, name='pages'),
As we already know, that is not the correct way to define URL for the application in Django-based framework. There must be a variable with the name of ‘urlpatterns’ with the type of list which is then assigned with those elements. So, the correct definition just by duplicating the pattern already exist in myproject\myproject\urls.py, it will exist as follows :
from django.contrib import admin from django.urls import path, re_path, include from app import views urlpatterns = [ # The home page path('', views.index, name='home'), # Matches any html file re_path(r'^.*\.*', views.pages, name='pages'), ]
Run the application again once more, if there are no other errors appear, the application will run normally.