很抱歉再次打扰,我正在研究我的第一个烧瓶项目,非常简单。
我在Digital Ocean,ubuntu服务器上部署我的网站。我遵守了instructions。
问题: 当我尝试在浏览器中打开网站时,出现500错误。然后我查看了apache错误日志以找到以下句子。
错误日志:
[Wed Dec 31 07:45:49 2014] [错误] [client 112.64.71.131] mod_wsgi(pid = 27835):目标WSGI脚本' /var/www/qianshan/qianshan.wsgi'无法作为Python模块加载。
[Wed Dec 31 07:45:49 2014] [错误] [client 112.64.71.131] mod_wsgi(pid = 27835):处理WSGI脚本' /var/www/qianshan/qianshan.wsgi时发生异常39;
[Wed Dec 31 07:45:49 2014] [错误] [client 112.64.71.131] Traceback(最近一次电话会议):
[Wed Dec 31 07:45:49 2014] [错误] [客户112.64.71.131]文件" /var/www/qianshan/qianshan.wsgi" ;,第7行,
[Wed Dec 31 07:45:49 2014] [错误] [客户端112.64.71.131]来自qianshan导入应用程序作为应用程序
[Wed Dec 31 07:45:49 2014] [错误] [client 112.64.71.131] ImportError:无法导入名称应用
项目的树结构
spark@Qianshan:/var/www/qianshan$ tree -L 2
.
├── qianshan
│ ├── config.ini
│ ├── qianshan.py
│ ├── static
│ ├── templates
│ └── venv
└── qianshan.wsgi
虚拟主机配置
<VirtualHost *:80>
ServerName qianshan.co
ServerAdmin spark@qianshan.co
WSGIScriptAlias / /var/www/qianshan/qianshan.wsgi
<Directory /var/www/qianshan/qianshan/>
Order allow,deny
Allow from all
</Directory>
Alias /static /var/www/qianshan/qianshan/static
<Directory /var/www/qianshan/qianshan/static/>
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
WSGI
#!/usr/bin/python
import sys
import logging
logging.basicConfig(stream=sys.stderr)
sys.path.insert(0,"/var/www/qianshan/")
from qianshan import app as application
application.secret_key = 'Add your secret key'
.py文件
# Filename: qianshan.py
# encoding: utf-8
import ConfigParser
import codecs
from flask import Flask
from flask import render_template
app = Flask(__name__)
@app.route('/')
def index():
block_list = getBlockList()
website_dict = getWebsiteDict()
return render_template('index.html', block_list=block_list, website_dict=website_dict)
...
...
if __name__ == '__main__':
app.run()
如果你足够幸运地看到这个底线,那么所有人都祝新年快乐^ _ ^
答案 0 :(得分:-1)
创建/var/www/qianshan/init.py文件,如下所示:
from flask import Flask
app = Flask(__name__)
import quianshan.quianshan #This is your view file.
然后从quianshan.py
中删除此行app = Flask(__name__)