将旧的Django项目部署到新主机

时间:2018-02-23 06:59:06

标签: python django python-2.7

我有Django 1.6项目,并使用Nginx Web服务器后面的Gunicorn Web应用程序服务器运行。现在我想将该项目转移到新主机。为此,我已经在新机器上复制了所有代码,并使用成功的pip install -r requirements.txt安装了所有必需的依赖项。

但之后如果我尝试执行以下任一python manage.py migratepython manage.py runserver 0.0.0.0:8000,则会出现以下错误:

Unhandled exception in thread started by <function wrapper at 0x7f9a114e1938>
Traceback (most recent call last):
  File "/var/www/html/forttottensquare/env/local/lib/python2.7/site-packages/django/utils/autoreload.py", line 93, in wrapper
    fn(*args, **kwargs)
  File "/var/www/html/forttottensquare/env/local/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 102, in inner_run
    self.validate(display_num_errors=True)
  File "/var/www/html/forttottensquare/env/local/lib/python2.7/site-packages/django/core/management/base.py", line 310, in validate
    num_errors = get_validation_errors(s, app)
  File "/var/www/html/forttottensquare/env/local/lib/python2.7/site-packages/django/core/management/validation.py", line 34, in get_validation_errors
    for (app_name, error) in get_app_errors().items():
  File "/var/www/html/forttottensquare/env/local/lib/python2.7/site-packages/django/db/models/loading.py", line 196, in get_app_errors
    self._populate()
  File "/var/www/html/forttottensquare/env/local/lib/python2.7/site-packages/django/db/models/loading.py", line 75, in _populate
    self.load_app(app_name, True)
  File "/var/www/html/forttottensquare/env/local/lib/python2.7/site-packages/django/db/models/loading.py", line 99, in load_app
    models = import_module('%s.models' % app_name)
  File "/var/www/html/forttottensquare/env/local/lib/python2.7/site-packages/django/utils/importlib.py", line 40, in import_module
    __import__(name)
  File "/var/www/html/forttottensquare/env/local/lib/python2.7/site-packages/filer/models/__init__.py", line 2, in <module>
    from filer.models.clipboardmodels import *
  File "/var/www/html/forttottensquare/env/local/lib/python2.7/site-packages/filer/models/clipboardmodels.py", line 7, in <module>
    from filer.models import filemodels
  File "/var/www/html/forttottensquare/env/local/lib/python2.7/site-packages/filer/models/filemodels.py", line 13, in <module>
    from polymorphic import PolymorphicModel, PolymorphicManager
  File "/var/www/html/forttottensquare/env/local/lib/python2.7/site-packages/polymorphic/__init__.py", line 13, in <module>
    _version_ = pkg_resources.require("django-polymorphic")[0].version
  File "/var/www/html/forttottensquare/env/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 984, in require
    needed = self.resolve(parse_requirements(requirements))
  File "/var/www/html/forttottensquare/env/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 875, in resolve
    raise VersionConflict(dist, req).with_context(dependent_req)
pkg_resources.ContextualVersionConflict: (Django 1.6.8 (/var/www/html/forttottensquare/env/lib/python2.7/site-packages), Requirement.parse('Django>=1.11'), set(['django-polymorphic']))
https://simpleisbetterthancomplex.com/tutorial/2016/10/14/how-to-deploy-to-digital-ocean.html

那怎么解决呢?

更新

执行pip install django-polymorphic==1.3之后,它会给出以下错误:

Unhandled exception in thread started by <function wrapper at 0x7f0dc09bd938>
Traceback (most recent call last):
  File "/var/www/html/forttottensquare/env/local/lib/python2.7/site-packages/django/utils/autoreload.py", line 93, in wrapper
    fn(*args, **kwargs)
  File "/var/www/html/forttottensquare/env/local/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 102, in inner_run
    self.validate(display_num_errors=True)
  File "/var/www/html/forttottensquare/env/local/lib/python2.7/site-packages/django/core/management/base.py", line 310, in validate
    num_errors = get_validation_errors(s, app)
  File "/var/www/html/forttottensquare/env/local/lib/python2.7/site-packages/django/core/management/validation.py", line 34, in get_validation_errors
    for (app_name, error) in get_app_errors().items():
  File "/var/www/html/forttottensquare/env/local/lib/python2.7/site-packages/django/db/models/loading.py", line 196, in get_app_errors
    self._populate()
  File "/var/www/html/forttottensquare/env/local/lib/python2.7/site-packages/django/db/models/loading.py", line 78, in _populate
    self.load_app(app_name)
  File "/var/www/html/forttottensquare/env/local/lib/python2.7/site-packages/django/db/models/loading.py", line 99, in load_app
    models = import_module('%s.models' % app_name)
  File "/var/www/html/forttottensquare/env/local/lib/python2.7/site-packages/django/utils/importlib.py", line 40, in import_module
    __import__(name)
  File "/var/www/html/forttottensquare/env/local/lib/python2.7/site-packages/filer/models/__init__.py", line 2, in <module>
    from filer.models.clipboardmodels import *
  File "/var/www/html/forttottensquare/env/local/lib/python2.7/site-packages/filer/models/clipboardmodels.py", line 7, in <module>
    from filer.models import filemodels
  File "/var/www/html/forttottensquare/env/local/lib/python2.7/site-packages/filer/models/filemodels.py", line 13, in <module>
    from polymorphic import PolymorphicModel, PolymorphicManager
ImportError: cannot import name PolymorphicModel

1 个答案:

答案 0 :(得分:2)

做(降级)

pip install django-polymorphic==1.3

如果不能正常工作,请使用旧版本。