How to Solve Error Message NameError ‘app’ is not defined when executing python runserver

Posted on

Another error involving the execution of a Django-based web application is in the content of this article. This article will discuss about how to solve the error message above. The error appear in the complete output as follows :

(env) user@hostname:~/python/django/todoproject$ python runserver
Watching for file changes with StatReloader
Performing system checks...

System check identified no issues (0 silenced).
March 15, 2020 - 02:37:45
Django version 2.2.6, using settings 'todoproject.settings'
Starting development server at
Quit the server with CONTROL-C.
/home/user/python/django/todoproject/todoproject/ changed, reloading.
Watching for file changes with StatReloader
Performing system checks...

Exception in thread django-main-thread:
Traceback (most recent call last):
  File "/home/user/anaconda3/lib/python3.7/", line 917, in _bootstrap_inner
  File "/home/user/anaconda3/lib/python3.7/", line 865, in run
    self._target(*self._args, **self._kwargs)
  File "/home/user/python/django/env/lib/python3.7/site-packages/django/utils/", line 54, in wrapper
    fn(*args, **kwargs)
  File "/home/user/python/django/env/lib/python3.7/site-packages/django/core/management/commands/", line 117, in inner_run
  File "/home/user/python/django/env/lib/python3.7/site-packages/django/core/management/", line 390, in check
  File "/home/user/python/django/env/lib/python3.7/site-packages/django/core/management/", line 377, in _run_checks
    return checks.run_checks(**kwargs)
  File "/home/user/python/django/env/lib/python3.7/site-packages/django/core/checks/", line 72, in run_checks
    new_errors = check(app_configs=app_configs)
  File "/home/user/python/django/env/lib/python3.7/site-packages/django/core/checks/", line 13, in check_url_config
    return check_resolver(resolver)
  File "/home/user/python/django/env/lib/python3.7/site-packages/django/core/checks/", line 23, in check_resolver
    return check_method()
  File "/home/user/python/django/env/lib/python3.7/site-packages/django/urls/", line 399, in check
    for pattern in self.url_patterns:
  File "/home/user/python/django/env/lib/python3.7/site-packages/django/utils/", line 80, in __get__
    res = instance.__dict__[] = self.func(instance)
  File "/home/user/python/django/env/lib/python3.7/site-packages/django/urls/", line 584, in url_patterns
    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
  File "/home/user/python/django/env/lib/python3.7/site-packages/django/utils/", line 80, in __get__
    res = instance.__dict__[] = self.func(instance)
  File "/home/user/python/django/env/lib/python3.7/site-packages/django/urls/", line 577, in urlconf_module
    return import_module(self.urlconf_name)
  File "/home/user/python/django/env/lib/python3.7/importlib/", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "", line 1006, in _gcd_import
  File "", line 983, in _find_and_load
  File "", line 967, in _find_and_load_unlocked
  File "", line 677, in _load_unlocked
  File "", line 728, in exec_module
  File "", line 219, in _call_with_frames_removed
  File "/home/user/python/django/todoproject/todoproject/", line 21, in 
NameError: name 'todoapp' is not defined

Apparently, the above error is actually giving complete information to solve the problem itself. Actually, python cannot solve the keyword ‘todoapp’. So, it need to be in a definition so that python will recognize and execute it. But the context of the problem actually exist in the following line as it appears in the error message ‘/home/user/python/django/todoproject/todoproject/’. The name of the app itself in this article’s context is ‘todoapp’. The following is the line causing the error message to appear :

    path('', include(todoapp.urls)),

In the file with the name of ‘’ where it is a file for specifying an additional url, it suddenly trigger an error. The additional url is imported from the application with the name of ‘todoapp’. The main intention is just to include a file with the name of ‘’ exist in the application folder with the name of ‘todoapp’. But python does not recognize this intention. Therefore, there is a need to modify the above line so that python will accept the import process of ‘’ in the folder todoapp. The solution is simple, just change the above line into the following one :

    path('', include('todoapp.urls')),

Make sure and do not forget to check whether the file with the name of ‘’ exist in the folder of ‘todoapp’. This article is part of the trial or experiment to simulate the lesson in the article with the title of ‘How to Build Todo App with Django’ in this link.

Leave a Reply