1、No module named ‘django.core.urlresolvers’

最近从django1.9迁移到django2.0中出现一个意外的报错:

from django.core.urlresolvers import reverse

# 报错
# No module named 'django.core.urlresolvers'

原因:django2.0把原来的django.core.urlresolvers包更改为了django.urls包。

解决方法是:把导入的包都修改一下。

# from django.core.urlresolvers import reverse
# 改为
from django.urls import reverse