"Import Error: No module named urls" with Django 1.8 and Rest Framework 3.7

"Import Error: No module named urls" with Django 1.8 and Rest Framework 3.7

我正在使用 django==1.8,rest_framework=3.7.7,python==2.7.12

urls.py

urlpatterns += [
     url(r'^api/core/', include('core.urls')),
]

core/urls.py

urlpatterns=[
    url(r'^/users/', core_view.userlist),
]

views.py

class UserList(generics.ListAPIView):
queryset = User.objects.all()
serializer_class = UserSerializer
userlist = UserList.as_view()

当我导航到:http://localhost:8000/api/core/users 我收到以下错误:

ImportError at /api/core/users
No module named urls
Request Method: GET
Request URL:    http://localhost:8000/api/core/users
Django Version: 1.8
Exception Type: ImportError
Exception Value:    
No module named urls
Exception Location: /usr/local/lib/python2.7/dist-packages/rest_framework/compat.py in <module>, line 26
Python Executable:  /usr/bin/python
Python Version: 2.7.12

配置有什么问题?

Django Rest Framework 不再支持 Django 1.8 in version 3.7

您应该安装较早版本的 rest framework,或升级 Django(请注意 Django 1.8 在 2018 年 4 月达到 end-of-life)

只需确保在 INSTALLED_APPS 设置中包含 core 应用程序,并且在核心目录文件夹中有 init.py。

查看 here 了解更多信息。