2017-02-07 112 views
0

我在Apache2 web服務器上部署Django應用程序時遇到了一些問題。我有這樣的錯誤:Apache2,Django。導入錯誤

ImportError: No module named 'myproject.settings'

但我不知道爲什麼。你可以幫幫我嗎?

我的配置文件:

<VirtualHost *:80> 
    Alias /static /var/www/myproject/myproject/static 
    <Directory /var/www/myproject/myproject/static> 
     Require all granted 
    </Directory> 

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

    WSGIDaemonProcess myproject python-path=/var/www/myproject python-home=/var/www/agora/ENV 
    WSGIProcessGroup myproject 
    WSGIScriptAlias//var/www/myproject/myproject/myproject/wsgi.py 

</VirtualHost> 

而且wsgi.py:

import os 
import sys 

path = '/var/www/myproject' 
if path not in sys.path: 
    sys.path.append(path) 

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

from django.core.wsgi import get_wsgi_application 
application = get_wsgi_application() 

項目的結構:

project 
|--ENV 
|--project 
|----project 
|------wsgi.py 
|------settings.py 
+0

'settings.py'在哪裏?你真的有'WSGIScriptAlias// var/www/myproject/myproject/myproject/wsgi.py'嗎?使用虛假名稱總是會使調試更加困難。 – Alasdair

+0

是的,在這裏嘗試路徑** wsgi.py **和** settings.py ** - **/var/www/agora/agora/agora ** – AndMar

回答

0

你的設置文件在/var/www/agora/agora/agora/settings.py,所以你需要/var/www/agora/agora在Python路徑。

目前,它看起來像你在python路徑上有python-path=/var/www/agora

如果您在Apache配置中正確設置了python路徑,那麼您不需要在wsgi.py文件中更改sys.path

+0

謝謝,它幫助了我。 – AndMar

0

你需要補充一點:

WSGIPythonPath /var/www/myproject/myproject 
+0

感謝您的回答。我試過了,但這並沒有幫助我 – AndMar