How to Solve Error Message ‘NameError: name ‘include’ is not defined when executing python runserver

Posted on

This is another article where the focus is to solve an error message occur when executing the command of ‘python runserver’. Well, it is a command to run a django application. Before the error occur, when the internal webserver for executing Django-based application is running, there is a source code modification. Editing the file with the name of ‘’ cause the following error appear :

(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 'include' is not defined

Actually, according to the above output command execution, the error is ‘NameError: name ‘include’ is not defined. This is an effect of defining or importing a Django-based application URL. This is the line of code specifying the import process :


It means, include the file with the name of ‘’ in the folder todoapp. But apparently, after finishing to define the above line, the error message of ‘NameError: name ‘include’ is not defined’ appear. Well, this is actully python doesn’t recognize the keyword of ‘include’. So, the solution is quite simple. Actually, ‘include’ is part of the library exist in Django. Therefore, just add the following line to import the library with the keyword of ‘include’. Just add the following line :

from django.urls import path,include

Finally, that step above will solve the error. As an additional information, the above source code is part of the lesson or article exist in this link with the title of ‘How to Build a Todo App with Django’.

Leave a Reply