我在当地开发了一个很棒的Flask应用程序..现在似乎无法为我的生活部署 .
我收到带有以下错误日志的内部服务器错误:
[Sat May 03 22:24:11.355281 2014] [:error] [pid 17560:tid 139814473037568] [client 68.40.196.121:52221] mod_wsgi (pid=17560): Target WSGI script '/var/www/dhh/dhh.wsgi' cannot be loaded as Python module.
[Sat May 03 22:24:11.355380 2014] [:error] [pid 17560:tid 139814473037568] [client 68.40.196.121:52221] mod_wsgi (pid=17560): Exception occurred processing WSGI script '/var/www/dhh/dhh.wsgi'.
[Sat May 03 22:24:11.355467 2014] [:error] [pid 17560:tid 139814473037568] [client 68.40.196.121:52221] Traceback (most recent call last):
[Sat May 03 22:24:11.355541 2014] [:error] [pid 17560:tid 139814473037568] [client 68.40.196.121:52221] File "/var/www/dhh/dhh.wsgi", line 7, in
[Sat May 03 22:24:11.355754 2014] [:error] [pid 17560:tid 139814473037568] [client 68.40.196.121:52221] from dhh.app import app as application
[Sat May 03 22:24:11.355815 2014] [:error] [pid 17560:tid 139814473037568] [client 68.40.196.121:52221] ImportError: No module named dhh.app
当前文件结构树:
/dhh
|--/app
|------/static
|------/templates
|------__init__.py
|------views.py
|--/flask
|------/bin
|------/include
|------/lib
|------/local
|--/tmp
相关文件
__init__.py
from flask import Flask
app = Flask(__name__)
from app import views
if __name__ == "__main__":
app.run()
views.py
from app import app
@app.route('/')
@app.route('/index')
def index():
return "Hello, World! This better get working soon."
/etc/apache2/sites-available/dhh.conf
ServerName davidhagan.me ServerAdmin david@davidhhagan.com WSGIScriptAlias / /var/www/dhh/dhh.wsgi Order allow,deny Allow from all Alias /static /var/www/dhh/dhh/app/static Order allow,deny Allow from all ErrorLog ${APACHE_LOG_DIR}/error.log LogLevel warn CustomLog ${APACHE_LOG_DIR}/access.log combined
dhh.wsgi
#!/usr/bin/python
import sys
import logging
logging.basicConfig(stream=sys.stderr)
sys.path.insert(0,"/var/www/dhh/")
from dhh.app import app as application
application.secret_key = 'super secret key'
虽然这是应用程序的非常空的版本,但它似乎导致了错误 . 我确定apache服务器是如何设置的,这是一个简单的错误,但无法用其他SO Q / A来解决它 . 我不想知道如何解决这个问题,但为什么会发生这种情况!
更新/解决方案
我最终需要改变路径以及我如何调用模块 .
sys.path.insert(0, "/var/www/dhh/")
变
sys.path.insert(0, "/var/www/dhh/dhh/")
和
from dhh.app import app as application
变
from app import app as application
1 回答
代替:
使用: