2013-04-26 53 views
1

我正面臨與django wsgi腳本相關的問題。我一直在使用兩個virtualenv作爲我的兩個應用程序,並且我已經在具有不同端口的本地服務器上部署了這兩個應用程序。對於第一個應用項目Apache配置文件看起來像:Apache服務器沒有使用適當的virtualenv與WSGI設置

listen 8081 
WSGIPythonPath /home/user/app1:/home/user/virtual-env1/lib/python2.7/site-packages 
<VirtualHost mylocalip:8081> 

     ServerAdmin [email protected] 

     ServerName www.app1.com 

     DocumentRoot /home/user/app1 

     <Directory /home/user/app1/static-root> 
       Options Indexes 
       Order Allow,Deny 
       Allow from all 
       IndexOptions FancyIndexing 
     </Directory> 

     <Directory /home/user/app1> 
       Options Indexes FollowSymLinks MultiViews 
       AllowOverride None 
       Order allow,deny 
       allow from all   
     </Directory> 

     WSGIScriptAlias//home/user/app1/django.wsgi 
     WSGIPassAuthorization On 
      Alias "/static" /home/user/workspace/app1/static_root 

</VirtualHost> 

和第二應用的Apache配置幾乎相同,而不是虛擬ENV1,但我使用虛擬ENV2和不同的端口。但是當我在服務器上運行我的第二個應用程序時,出現了這個錯誤。

**AttributeError at /** 
    'Settings' object has no attribute 'DB_FILES' 
     Request Method: GET 
     Request URL: http://mylocalip:8091/ 
     Django Version: 1.4.3 
     Exception Type: AttributeError 
     Exception Value: 'Settings' object has no attribute 'DB_FILES' 
     Exception Location: /home/user/virtual-env1/lib/python2.7/site-packages/django/utils/functional.py in inner, line 185 
     Python Executable: /usr/bin/python 
     Python Version: 2.7.2 
     Python Path: 
     ['/home/user/virtual-env1/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg', 
     '/home/user/virtual-env1/lib/python2.7/site-packages/pip-1.1-py2.7.egg', 
     '/home/user/app1', 
     '/home/user/virtual-env1/lib/python2.7/site-packages', 
     '/usr/local/lib/python2.7/dist-packages/pip-1.1-py2.7.egg', 
     '/usr/local/lib/python2.7/dist-packages', 
     '/usr/lib/python2.7', 
     '/usr/lib/python2.7/plat-linux2', 
     '/usr/lib/python2.7/lib-tk', 
     '/usr/lib/python2.7/lib-old', 
     '/usr/lib/python2.7/lib-dynload', 
     '/usr/local/lib/python2.7/dist-packages', 
     '/usr/lib/python2.7/dist-packages', 
     '/usr/lib/python2.7/dist-packages/PIL', 
     '/usr/lib/python2.7/dist-packages/gst-0.10', 
     '/usr/lib/python2.7/dist-packages/gtk-2.0', 
     '/usr/lib/pymodules/python2.7', 
     '/usr/lib/python2.7/dist-packages/ubuntu-sso-client', 
     '/usr/lib/python2.7/dist-packages/ubuntuone-client', 
     '/usr/lib/python2.7/dist-packages/ubuntuone-control-panel', 
     '/usr/lib/python2.7/dist-packages/ubuntuone-couch', 
     '/usr/lib/python2.7/dist-packages/ubuntuone-installer', 
     '/usr/lib/python2.7/dist-packages/ubuntuone-storage-protocol', 
     '/home/user/app2', 
     '/home'] 

我django.wsgi文件loks這樣的:

import os, sys 

apache_configuration = os.path.dirname (__file__) 

project = os.path.dirname (apache_configuration) 

workspace = os.path.dirname (project) 

sys.path.append ("/home/user/app2") 

sys.path.append (workspace) 

os.environ ['DJANGO_SETTINGS_MODULE'] = 'app2.settings' 


import django.core.handlers.wsgi 

application = django.core.handlers.wsgi.WSGIHandler() 

我不知道爲什麼我的服務器正在虛擬-ENV1,而不是虛擬ENV2內。請幫助我,因爲我是django和wsgi的新手。

回答

3

這是什麼幫助我在類似的情況。

我WSGI文件看起來像這樣:

import os 
import sys 

# activate venv 
activate_this = 'full_path_to_activate_this.py' 
execfile(activate_this, dict(__file__=activate_this)) 

# insert project path to sys path 
path = 'full_path_to_your_project' 
if path not in sys.path: 
    sys.path.insert(0, path) 

import django.core.handlers.wsgi 
os.environ['DJANGO_SETTINGS_MODULE'] = 'your_settings' 
application = django.core.handlers.wsgi.WSGIHandler() 

可能這是不是最好的方法,但它爲我工作。

我記得我GOOGLE了,發現了很多不同的解決方案,這裏的一些相關鏈接:

希望有所幫助。

+0

::你可以描述什麼是'full_path_to_activate_this.py',因爲我是全新的django – 2013-04-26 11:29:06

+1

'activate_this'應該位於'bin'目錄下的virtualenv文件夾中。 – alecxe 2013-04-26 11:36:21

+0

謝謝,你的WSGI文件已經爲我工作。 – 2013-04-26 11:47:26

相關問題