No module named 'django.core.urlresolvers'

No module named 'django.core.urlresolvers'
解决方法就是:

from django.urls import reverse

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

No module named 'django.core.urlresolvers

简单来说,原因就是:django2.0 把原来的 django.core.urlresolvers 包 更改为了 django.urls包,所以我们需要把导入的包都修改一下就可以了。


Reverse for 'post_detail' not found. 'post_detail' is not a valid view function or pattern name.
源于之前定义的为blog_detail URL,blog为命名空间,具体的对象是Post,应为Post对象构建标准URL,

urlpatterns = [
    path('/', views.DetailView.as_view(), name='blog_detail'),
]

改为

urlpatterns = [
    path('/', views.DetailView.as_view(), name='post_detail'),
]

Reverse for 'post_detail' with arguments '(2018, '05', '16', 'tesila')' not found
源于get_absolute_url传参与urlpatterns 所需参数之间不对应

def get_absolute_url(self):
        return reverse('blog:post_detail',
                        args=[self.publish.year,
                              self.publish.strftime('%m'),
                              self.publish.strftime('%d'),
                              self.slug])

改为

def get_absolute_url(self):
        return reverse('blog:post_detail',
                        args=[self.id])

你可能感兴趣的:(No module named 'django.core.urlresolvers')