部署在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 [email protected]
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()
祝大家新年快乐
1
imlonghao 2015-01-02 12:35:30 +08:00 via Android
ImportError: cannot import name app
|
2
imlonghao 2015-01-02 12:36:31 +08:00 via Android
from qianshan import app
qianshan目录下哪里有app? |
3
Livid MOD 看起来像是 working directory 问题。
|
4
crazyxin1988 2015-01-02 13:11:49 +08:00 2
|
5
imlonghao 2015-01-02 13:12:50 +08:00 via Android
收回2L说的话 自己对Flask不熟造成
|
6
HowardMei 2015-01-02 13:18:46 +08:00
你第一条 Allow from all 会把 config.ini 也暴露了吧?
|
7
teannnn OP |
8
crazyxin1988 2015-01-02 20:32:44 +08:00 1
@teannnn
还没搞定? 我昨晚在sf上回答你了~ 我觉得 你有些的东西没搞清楚~ 推荐你仔细看一下flask官方文档 http://flask.pocoo.org/docs/0.10/deploying/mod_wsgi/ 搞清楚大体的原理再去弄~很快的 文档里说的很清楚 sys.path.insert(0,"path") 的用途是:项目使用virtualenv,然后项目的所有的所以依赖库都是安装在了项目下,在你的项目里就是venv 这里~ |
9
teannnn OP @crazyxin1988 好,多谢
|
10
teannnn OP |
11
teannnn OP 我在检查代码中,谢谢大家。上面的python代码是教程中的
|