[django] ImportError: No module named 'django.core.urlresolvers'

I am working on Django project where I need to create a form for inputs. I tried to import reverse from django.core.urlresolvers. I got an error:

line 2, in from django.core.urlresolvers import reverse ImportError: No module named 'django.core.urlresolvers'

I am using Python 3.5.2, Django 2.0 and MySQL.

This question is related to django python-3.x python-3.5 django-2.0

The answer is


If your builds on TravisCI are failing for this particular reason, you can resolve the issue by updating the Django Extensions in your requirements.txt

pip install --upgrade django-extensions

This will update the extensions to use Django 2+ modules.


You need replace all occurrences of:

from django.core.urlresolvers import reverse

to:

from django.urls import reverse

enter image description here

NOTE: The same apply to reverse_lazy

in Pycharm Cmd+Shift+R for starting replacment in Path.


In my case the problem was that I had outdated django-stronghold installed (0.2.9). And even though in the code I had:

from django.urls import reverse

I still encountered the error. After I upgraded the version to django-stronghold==0.4.0 the problem disappeard.


For django version greater than 2.0 use:

from django.urls import reverse

in your models.py file.


To solve this either you down-grade the Django to any version lesser than 2.0. pip install Django==1.11.29.


use from django.urls import reverse instead of from django.core.urlresolvers import reverse


if you want to import reverse, import it from django.urls

from django.urls import reverse

For those who might be trying to create a Travis Build, the default path from which Django is installed from the requirements.txt file points to a repo whose django_extensions module has not been updated. The only workaround, for now, is to install from the master branch using pip. That is where the patch is made. But for now, we'll have to wait.

You can try this in the meantime, it might help

- pip install git+https://github.com/chibisov/drf-extensions.git@master

- pip install git+https://github.com/django-extensions/django-extensions.git@master


urlresolver has been removed in the higher version of Django - Please upgrade your django installation. I fixed it using the following command.

pip install django==2.0 --upgrade

use this one:

from django.urls import reverse

Examples related to django

How to fix error "ERROR: Command errored out with exit status 1: python." when trying to install django-heroku using pip Pylint "unresolved import" error in Visual Studio Code Is it better to use path() or url() in urls.py for django 2.0? Unable to import path from django.urls Error loading MySQLdb Module 'Did you install mysqlclient or MySQL-python?' ImportError: Couldn't import Django Django - Reverse for '' not found. '' is not a valid view function or pattern name Class has no objects member Getting TypeError: __init__() missing 1 required positional argument: 'on_delete' when trying to add parent table after child table with entries How to switch Python versions in Terminal?

Examples related to python-3.x

Could not load dynamic library 'cudart64_101.dll' on tensorflow CPU-only installation Replace specific text with a redacted version using Python Upgrade to python 3.8 using conda "Permission Denied" trying to run Python on Windows 10 Python: 'ModuleNotFoundError' when trying to import module from imported package What is the meaning of "Failed building wheel for X" in pip install? How to downgrade python from 3.7 to 3.6 I can't install pyaudio on Windows? How to solve "error: Microsoft Visual C++ 14.0 is required."? Iterating over arrays in Python 3 How to upgrade Python version to 3.7?

Examples related to python-3.5

ImportError: No module named 'django.core.urlresolvers' 'python3' is not recognized as an internal or external command, operable program or batch file pip not working in Python Installation in Windows 10 installing cPickle with python 3.5 Difference between numpy dot() and Python 3.5+ matrix multiplication @ How to specify multiple return types using type-hints What are type hints in Python 3.5?

Examples related to django-2.0

Getting TypeError: __init__() missing 1 required positional argument: 'on_delete' when trying to add parent table after child table with entries ImportError: No module named 'django.core.urlresolvers'