Introduction
As soon as fixing the error message appear in the previous article, there is another error message appear. The previous article exist in this link with the title of ‘How to Solve Error Message RuntimeError: Model class django.contrib.sites.models.Site doesn’t declare an explicit app_label and isn’t in an application in INSTALLED_APPS in Django Application’. So, after solving that problem, there is another problem which is available by the appearance of another different error message. That error message exist as in the title of this article. But it can be either way which error message appear first apparently with the other one in the other article. The error message in short appear at the end of the execution of the ‘python manage.py runserver’ as follows :
RuntimeError: Model class django.contrib.flatpages.models.FlatPage doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.
The long or the complete form showing the error message actually appear as follows :
(env) C:\programming\python\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:\app\python39\lib\threading.py", line 973, in _bootstrap_inner self.run() File "C:\app\python39\lib\threading.py", line 910, in run self._target(*self._args, **self._kwargs) File "C:\app\python39\lib\site-packages\django\utils\autoreload.py", line 64, in wrapper fn(*args, **kwargs) File "C:\app\python39\lib\site-packages\django\core\management\commands\runserver.py", line 118, in inner_run self.check(display_num_errors=True) File "C:\app\python39\lib\site-packages\django\core\management\base.py", line 419, in check all_issues = checks.run_checks( File "C:\app\python39\lib\site-packages\django\core\checks\registry.py", line 76, in run_checks new_errors = check(app_configs=app_configs, databases=databases) File "C:\app\python39\lib\site-packages\django\core\checks\urls.py", line 13, in check_url_config return check_resolver(resolver) File "C:\app\python39\lib\site-packages\django\core\checks\urls.py", line 23, in check_resolver return check_method() File "C:\app\python39\lib\site-packages\django\urls\resolvers.py", line 412, in check for pattern in self.url_patterns: File "C:\app\python39\lib\site-packages\django\utils\functional.py", line 48, in __get__ res = instance.__dict__[self.name] = self.func(instance) File "C:\app\python39\lib\site-packages\django\urls\resolvers.py", line 598, in url_patterns patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module) File "C:\app\python39\lib\site-packages\django\utils\functional.py", line 48, in __get__ res = instance.__dict__[self.name] = self.func(instance) File "C:\app\python39\lib\site-packages\django\urls\resolvers.py", line 591, in urlconf_module return import_module(self.urlconf_name) File "C:\app\python39\lib\importlib\__init__.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 1030, in _gcd_import File "<frozen importlib._bootstrap>", line 1007, in _find_and_load File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 680, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 850, in exec_module File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed File "C:\programming\python\myproject\myproject\urls.py", line 26, in <module> path('pages/', include('django.contrib.flatpages.urls')), File "C:\app\python39\lib\site-packages\django\urls\conf.py", line 34, in include urlconf_module = import_module(urlconf_module) File "C:\app\python39\lib\importlib\__init__.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 1030, in _gcd_import File "<frozen importlib._bootstrap>", line 1007, in _find_and_load File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 680, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 850, in exec_module File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed File "C:\app\python39\lib\site-packages\django\contrib\flatpages\urls.py", line 1, in <module> from django.contrib.flatpages import views File "C:\app\python39\lib\site-packages\django\contrib\flatpages\views.py", line 2, in <module> from django.contrib.flatpages.models import FlatPage File "C:\app\python39\lib\site-packages\django\contrib\flatpages\models.py", line 8, in <module> class FlatPage(models.Model): File "C:\app\python39\lib\site-packages\django\db\models\base.py", line 113, in __new__ raise RuntimeError( RuntimeError: Model class django.contrib.flatpages.models.FlatPage doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.
Solution
Actually, the solution is similar with the other article triggering different message. Since the tone of the error message is similar because it is about a class which is not available in the application definition. As another proper solution, just add one single line in the ‘settings.py’ file exist in the folder project of the Django-based framework to solve it. The solution just by adding the following line :
'django.contrib.flatpages',
By adding the above line, the entire definition of the INSTALLED_APPS constant will be in the following appearance :
# Application definition INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'django.contrib.sites', 'django.contrib.flatpages', 'crispy_forms', 'myproject', 'mptt', ]
Finally, running or executing the Django-based internal service once more. It will end in a success if there are no more error appear.