Python
Django
ImportError
urlresolvers
troubleshooting

ImportError No module named 'django.core.urlresolvers'

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

The error ImportError: No module named 'django.core.urlresolvers' usually means your code or one of your dependencies is using an old Django import path. The fix is straightforward once you know the history: URL resolution helpers were moved out of django.core.urlresolvers and into django.urls.

Why the Import Broke

In older Django versions, functions such as reverse and resolve lived in django.core.urlresolvers. That path was deprecated in Django 1.10 and removed in Django 2.0, so newer projects must import them from django.urls.

Old code:

python
from django.core.urlresolvers import reverse
from django.core.urlresolvers import resolve
from django.core.urlresolvers import NoReverseMatch

Updated code:

python
from django.urls import reverse
from django.urls import resolve
from django.urls import NoReverseMatch

If the error appears after a Django upgrade, this import change is the first thing to check.

The same fix applies whether the import appears in views, tests, forms, middleware, or utility modules. The old module name is the problem, not the location where it happens to be used.

Update Your Own Code First

Search your project for the old import path and replace it everywhere. The most common replacements are:

  • 'reverse'
  • 'reverse_lazy'
  • 'resolve'
  • 'Resolver404'
  • 'NoReverseMatch'

For example, this class-based view import:

python
from django.core.urlresolvers import reverse_lazy

should become:

python
from django.urls import reverse_lazy

After updating imports, run your tests or start the development server again to catch any remaining references.

What If a Third-Party Package Still Uses It

Sometimes the problem is not in your code but in an older dependency. In that case, inspect the traceback carefully to find the file that imports django.core.urlresolvers.

You generally have three options:

  1. upgrade the package to a Django-compatible version
  2. replace the package with a maintained alternative
  3. patch the dependency temporarily if you are blocked

A quick local patch looks like this:

python
1# old
2from django.core.urlresolvers import reverse
3
4# new
5from django.urls import reverse

A temporary monkey patch is possible but usually a bad idea. It hides the compatibility issue instead of fixing it cleanly.

If the dependency is unmaintained and you must keep it for a while, fork it or vendor the patched version explicitly so the change is tracked in version control. Silent edits inside the virtual environment are hard to reproduce later.

Check Your Django Version Explicitly

If you are unsure which version of Django is active in the environment, verify it from the shell:

bash
python -m django --version

Or from Python:

python
import django
print(django.get_version())

This matters because mixed virtual environments are a common source of confusion. You might be editing code for one project while running another interpreter that has a different Django version installed.

If you use pip, it is also worth checking the exact installed package metadata:

bash
python -m pip show django

That confirms the interpreter path and the installed version together, which is often enough to spot an environment mismatch.

Common Pitfalls

  • Updating one import and missing other old names such as reverse_lazy or Resolver404.
  • Assuming the issue is in your app code when the traceback actually points to a third-party package.
  • Patching the installed package manually and forgetting that the change will be lost on reinstall.
  • Ignoring the active virtual environment and checking the wrong Django version.
  • Searching only application code and forgetting tests, management commands, and older migration helpers that may still import the deprecated path.

Summary

  • 'django.core.urlresolvers is an old import path removed from modern Django versions.'
  • Replace imports with equivalents from django.urls.
  • Check both your code and third-party dependencies.
  • Confirm the Django version running in the current environment.
  • Prefer upgrading dependencies over carrying compatibility hacks.

Course illustration
Course illustration

All Rights Reserved.