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

流过昼夜 提交于 2019-11-27 00:29:19
knbk

Django 2.0 removes the django.core.urlresolvers module, which was moved to django.urls in version 1.10. You should change any import to use django.urls instead, like this:

from django.urls import reverse

Note that Django 2.0 removes some features that previously were in django.core.urlresolvers, so you might have to make some more changes before your code works. See the features deprecated in 1.9 for details on those additional changes.

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

from django.urls import reverse

You need replace all occurrences of:

from django.core.urlresolvers import reverse

to:

from django.urls import reverse

NOTE: The same apply to reverse_lazy

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

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

naimur rahman

use this one:

from django.urls import reverse

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.

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

You can create a symbolic link without problem.

cd site-packages/django/core
ln -s ../urls/ urlresolvers

And that's all.

This is useful for not updated packages that still search in the old path.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!