這是一件很奇怪的事情,我無法理解它。無法在apache服務器上的django中加載模塊錯誤
這是短暫的
project/
apache/ django.wsgi
project/ __init__.py, settings.py, urls.py ..
services/
__init__.py
apis/
__init__.py
fparser.py
wservice.py
...
profile.py
所以我的Django的文件目錄結構,一切都運行在開發服務器,甚至在Heroku(gunicorn)罰款,但不工作在Apache(本地主機)
時我打開的頁面:
其顯示
Exception Type: ImportError at/
Exception Value: cannot import name website_feed_address
這個website_feed_address
位於profile.py import error
被發現在fparser.py
我該如何解決它?
編輯:
django.wsgi
import os, sys
sys.path.append('d:/code/projects-dev/project')
os.environ['DJANGO_SETTINGS_MODULE'] = 'project.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
,而在上面的問題中提到的項目目錄層次結構是d:/code/projects-dev/
編輯2
這些都是Apache日誌錯誤
[Sun Jul 08 23:14:04 2012] [notice] Parent: Received restart signal -- Restarting the server.
httpd.exe: Could not reliably determine the server's fully qualified domain name, using 124.123.136.220 for ServerName
[Sun Jul 08 23:14:04 2012] [warn] mod_wsgi: Compiled for Python/2.7.
[Sun Jul 08 23:14:04 2012] [warn] mod_wsgi: Runtime using Python/2.7.2.
[Sun Jul 08 23:14:05 2012] [notice] Child 5912: Exit event signaled. Child process is ending.
[Sun Jul 08 23:14:05 2012] [warn] RSA server certificate CommonName (CN) `127.0.0.1' does NOT match server name!?
[Sun Jul 08 23:14:05 2012] [notice] Apache/2.2.22 (Win32) mod_wsgi/3.3 Python/2.7.2 mod_ssl/2.2.22 OpenSSL/0.9.8t configured -- resuming normal operations
[Sun Jul 08 23:14:05 2012] [notice] Server built: Jan 28 2012 11:16:39
[Sun Jul 08 23:14:05 2012] [notice] Parent: Created child process 2120
httpd.exe: Could not reliably determine the server's fully qualified domain name, using 124.123.136.220 for ServerName
[Sun Jul 08 23:14:05 2012] [warn] RSA server certificate CommonName (CN) `127.0.0.1' does NOT match server name!?
httpd.exe: Could not reliably determine the server's fully qualified domain name, using 124.123.136.220 for ServerName
[Sun Jul 08 23:14:05 2012] [warn] mod_wsgi: Compiled for Python/2.7.
[Sun Jul 08 23:14:05 2012] [warn] mod_wsgi: Runtime using Python/2.7.2.
[Sun Jul 08 23:14:05 2012] [warn] RSA server certificate CommonName (CN) `127.0.0.1' does NOT match server name!?
[Sun Jul 08 23:14:05 2012] [notice] Child 2120: Child process is running
[Sun Jul 08 23:14:06 2012] [notice] Child 2120: Acquired the start mutex.
[Sun Jul 08 23:14:06 2012] [notice] Child 5912: Released the start mutex
[Sun Jul 08 23:14:06 2012] [notice] Child 2120: Starting 64 worker threads.
[Sun Jul 08 23:14:06 2012] [notice] Child 2120: Starting thread to listen on port 443.
[Sun Jul 08 23:14:06 2012] [notice] Child 2120: Starting thread to listen on port 80.
[Sun Jul 08 23:14:07 2012] [notice] Child 5912: Terminating 126 threads that failed to exit.
[Sun Jul 08 23:14:07 2012] [notice] Child 5912: All worker threads have exited.
[Sun Jul 08 23:14:07 2012] [notice] Child 5912: Child process is exiting
編輯3
這是怎麼profile.py,fparser.py看
profile.py
只包含一些變量,元組就像settings.py
。它只是在這種情況下導入變量website_feed_address
。
這是fparser.py
from profile import website_feed_address
import feedparser
class FParser(object):
def __init__(self):
self.pFeed = feedparser.parse(website_feed_address)
# rest of the code goes...
我只是想使用FParser類website_feed_address沒有 把它作爲一個對象參數。有沒有更好的方法呢?或者 別的,我可以像這樣使用它嗎?
你如何定義Apache使用的PYTHONPATH?你如何導入'website_feed_address'? – Rodrigue 2012-07-08 15:34:44
@Rodrigue以及我使用Eclipse ..大部分PATH類的東西都由它來照顧。關於django.wsgi,我在上面的問題中增加了更多細節。請檢查它 – Surya 2012-07-08 15:39:44