尝试在生产中部署一个应用程序,获取这个名为' django.urls'错误

时间:2018-02-23 22:38:31

标签: python django python-3.x

  

Django版本:1.8 Python版本:3.5.2

当我在生产中运行此应用程序时,从Windows到Linux PC时出现此错误

Installed Applications:
('django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'rest_framework',
 'dasboard')


Traceback:
File "/home/ubuntu/var/www/django_env/lib/python3.5/site-packages/django/core/handlers/base.py" in get_response
  119.                 resolver_match = resolver.resolve(request.path_info)
File "/home/ubuntu/var/www/django_env/lib/python3.5/site-packages/django/core/urlresolvers.py" in resolve
  366.             for pattern in self.url_patterns:
File "/home/ubuntu/var/www/django_env/lib/python3.5/site-packages/django/core/urlresolvers.py" in url_patterns
  402.         patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/home/ubuntu/var/www/django_env/lib/python3.5/site-packages/django/core/urlresolvers.py" in urlconf_module
  396.             self._urlconf_module = import_module(self.urlconf_name)
File "/home/ubuntu/var/www/django_env/lib/python3.5/importlib/__init__.py" in import_module
  126.     return _bootstrap._gcd_import(name[level:], package, level)
File "/home/ubuntu/var/www/mydashboard/mydashboard/urls.py" in <module>
  3. from dasboard import views
File "/home/ubuntu/var/www/mydashboard/dasboard/views.py" in <module>
  6. from rest_framework.response import Response
File "/home/ubuntu/var/www/django_env/lib/python3.5/site-packages/rest_framework/response.py" in <module>
  13. from rest_framework.serializers import Serializer
File "/home/ubuntu/var/www/django_env/lib/python3.5/site-packages/rest_framework/serializers.py" in <module>
  30. from rest_framework.compat import postgres_fields, unicode_to_repr
File "/home/ubuntu/var/www/django_env/lib/python3.5/site-packages/rest_framework/compat.py" in <module>
  26.     from django.urls import (  **# noqa**

Exception Type: ImportError at /
Exception Value: No module named 'django.urls'

This is the Project Heirarchy

我没有使用Postgres简单的sqlite db ..

请帮忙!

2 个答案:

答案 0 :(得分:2)

检查你的django rest框架版本,当前版本(3.7)不支持django 1.8。你需要rest_framework 3.6才能在django 1.8上运行

答案 1 :(得分:0)

这似乎是因为settings.py文件中的ROOT_URLCONF设置指向不存在的文件。转到项目中的settings.py文件并将其设置为以下内容:

ROOT_URLCONF = 'mydashboard.urls'