简体   繁体   English

Django生产部署

[英]Django Deployment for Production

I have Django running on my local machine, but I am at the point to where I want to deploy my Django site to my production server. 我在本地计算机上运行了Django,但是现在我想将Django站点部署到生产服务器上。 My server is an Ubuntu 14.04 server, with Apache 2.x, python 2.7, and Django 1.8. 我的服务器是Ubuntu 14.04服务器,具有Apache 2.x,python 2.7和Django 1.8。 I have tried using Django's basic configuration for Apache and mod_wsgi link , but I keep getting the following error: 我已经尝试将Django的基本配置用于Apache和mod_wsgi 链接 ,但我一直收到以下错误:

my site 我的网站

Internal Server Error 内部服务器错误

The server encountered an internal error or misconfiguration and was unable to complete your request. 服务器遇到内部错误或配置错误,无法完成您的请求。

Here is the error in the Apache Error Log I am receiving: 这是我收到的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',  

Here is my apache2.conf file: 这是我的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

This is my wsgi.py file: 这是我的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()

This is my websites .conf file: 这是我的网站.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>

Any help would be greatly appreciated. 任何帮助将不胜感激。 If there is anything else I can post to help out let me know. 如果还有其他可以帮忙的地方,请告诉我。

Your system is probably using an older version of the six python package that doesn't contain the python_2_unicode_compatible method. 您的系统可能正在使用不包含python_2_unicode_compatible方法的six python软件包的旧版本。 Upgrading six to the latest version should fix it: 将六个升级到最新版本应该可以解决此问题:

pip install --upgrade six

That said, it is strongly advisable to run Django from a virtual environment instead of installing packages at the system level - if there are system packages that for some reason are dependent on the older version of six then you may run into other problems. 就是说,强烈建议从虚拟环境中运行Django,而不是在系统级别安装软件包-如果某些系统软件包由于某种原因依赖于six旧版本,那么您可能会遇到其他问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM