部署在Digital Ocean的ubuntu 12.X主机上。这个是DO的部署说明如何在ubuntu上部署Flask应用
Problem:
浏览器访问地址后,报500错误。接着我检查了apache日志,报错如下
Error log
[Thu Jan 01 23:13:29 2015] [error] [client 112.64.71.131] mod_wsgi (pid=6887): Target WSGI script '/var/www/qianshan/qianshan.wsgi' cannot be loaded as Python module.
[Thu Jan 01 23:13:29 2015] [error] [client 112.64.71.131] mod_wsgi (pid=6887): Exception occurred processing WSGI script '/var/www/qianshan/qianshan.wsgi'.
[Thu Jan 01 23:13:29 2015] [error] [client 112.64.71.131] Traceback (most recent call last):
[Thu Jan 01 23:13:29 2015] [error] [client 112.64.71.131] File "/var/www/qianshan/qianshan.wsgi", line 7, in <module>
[Thu Jan 01 23:13:29 2015] [error] [client 112.64.71.131] from qianshan import app as application
[Thu Jan 01 23:13:29 2015] [error] [client 112.64.71.131] ImportError: cannot import name app
树形结构
qianshan
├── qianshan
│ ├── config.ini
│ ├── __init__.py
│ ├── static
│ ├── templates
│ └── venv
└── qianshan.wsgi
Virtual Host configuration
<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'
init.py file
# Filename: __init__.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()
祝大家新年快乐
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.