2016-05-13 125 views
0

我有我的本地機器上運行的Django,但我到了我想要將我的Django站點部署到我的生產服務器的位置。我的服務器是Ubuntu 14.04服務器,具有Apache 2.x,Python 2.7和Django 1.8。我一直在使用Django的基本配置Apache和mod_wsgi的link試過,但我不斷收到以下錯誤:Django生產部署

my site

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

這裏是在Apache的錯誤日誌我收到的錯誤:

mod_wsgi (pid=14962): Target WSGI script '/var/www/tmws/tmws/wsgi.py' cannot be loaded as Python module., 
mod_wsgi (pid=14962): Exception occurred processing WSGI script '/var/www/tmws/tmws/wsgi.py'., 
Traceback (most recent call last):, 
File "/var/www/tmws/tmws/wsgi.py", line 21, in <module>, 
    application = get_wsgi_application(), 
File "/usr/local/lib/python2.7/dist-packages/django/core/wsgi.py", line 14, in get_wsgi_application, 
    django.setup(), 
File "/usr/local/lib/python2.7/dist-packages/django/__init__.py", line 18, in setup, 
    apps.populate(settings.INSTALLED_APPS), 
File "/usr/local/lib/python2.7/dist-packages/django/apps/registry.py", line 85, in populate, 
    app_config = AppConfig.create(entry), 
File "/usr/local/lib/python2.7/dist-packages/django/apps/config.py", line 86, in create, 
    module = import_module(entry), 
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module, 
    __import__(name), 
File "/var/www/tmws/django_tables2/__init__.py", line 2, in <module>, 
    from .tables import Table, 
File "/var/www/tmws/django_tables2/tables.py", line 15, in <module>, 
    from . import columns, 
File "/var/www/tmws/django_tables2/columns/__init__.py", line 1, in <module>, 
    from .base import library, BoundColumn, BoundColumns, Column, 
File "/var/www/tmws/django_tables2/columns/base.py", line 10, in <module>, 
    from django_tables2.utils import Accessor, AttributeDict, OrderBy, OrderByTuple, 
File "/var/www/tmws/django_tables2/utils.py", line 111, in <module>, 
    @six.python_2_unicode_compatible, 
AttributeError: 'module' object has no attribute 'python_2_unicode_compatible', 

這裏是我的apache2.conf文件:

... 

<Directory /var/www/tmws/tmws> 
    <Files wsgi.py> 
     Require all granted 
    </Files> 
</Directory> 

... 

WSGIScriptAlias//var/www/tmws/tmws/wsgi.py 
WSGIPythonPath /var/www/tmws 

這是我wsgi.py文件:

import os, sys 

from django.core.wsgi import get_wsgi_application 

sys.path.append('/home/ubuntu/gather/src') 
sys.path.append('/usr/local/lib/python2.7/dist-packages') 
sys.path.append('/var/www/tmws') 
sys.path.append('/var/www/tmws/tmws') 

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "tmws.settings") 

application = get_wsgi_application() 

這是我的網站.conf文件:

<VirtualHost *:80> 
    ServerAdmin xxxxxxxx 
    ServerName xxxxxxxxxxx 
    DocumentRoot /var/www/tmws 
    WSGIScriptAlias//var/www/tmws/tmws/wsgi.py 

    ErrorLog ${APACHE_LOG_DIR}/TMWSerror.log 
    CustomLog ${APACHE_LOG_DIR}/TMWSaccess.log combined 

</VirtualHost> 

任何幫助將不勝感激。如果有什麼我可以張貼幫助瞭解我。

+0

您是否正在虛擬環境中運行Django?你可能應該。問題是你使用的是舊版本的'six'。 – solarissmoke

+0

謝謝你的迴應。不,我不使用虛擬環境,最終我想。六是什麼? – user908759

+3

'six'是一個python庫。如果你使用'pip install --upgrade six'升級它,它應該可以工作,但是在系統上python軟件包這樣做並不理想,因爲你可能會與其他系統軟件包發生衝突 - 因此更好地使用虛擬環境。 – solarissmoke

回答

1

您的系統可能正在使用舊版本的six python軟件包,該軟件包不包含python_2_unicode_compatible方法。升級六到最新的版本應該修復它:

pip install --upgrade six 

這就是說,它是強烈建議從虛擬環境,而不是在系統級安裝軟件包運行Django的 - 如果有系統的軟件包,由於某些原因是依賴於舊版本的six,那麼你可能會遇到其他問題。