应用程序使用python run.py
在本地工作但是当使用Apache部署到Ubuntu VPS时,它会产生500错误。
Apache Logs返回:
File "/var/www/ssapi/venv/lib/python2.7/site-packages/flask/app.py", line 28, in <module>, referer: http://api.soundshelter.net/
[Fri Jun 03 04:20:47.336788 2016] [:error] [pid 26915] [client 64.245.52.2:57465] from .config import ConfigAttribute, Config, referer: http://api.soundshelter.net/
[Fri Jun 03 04:20:47.336819 2016] [:error] [pid 26915] [client 64.245.52.2:57465] ImportError: No module named config, referer: http://api.soundshelter.net/
目录结构
init.py
from flask import Flask
import config
from . import *
app = Flask(__name__)
app.config.from_object('config')
api.py
#!flask/bin/python
from flask import Flask, request, render_template, jsonify,abort, make_response
#http://flask.pocoo.org/snippets/9/
from werkzeug.contrib.cache import SimpleCache
import collections
#database connect
from flaskext.mysql import MySQL
import json
import sys
import sys, os
sys.path.append('/var/www/ssapi')
import config
reload(sys)
sys.setdefaultencoding('utf-8')
app = Flask(__name__)
app.config.from_object('config')
app.config['MYSQL_DATABASE_USER'] = config.user
app.config['MYSQL_DATABASE_PASSWORD'] = config.password
app.config['MYSQL_DATABASE_DB'] = config.database
app.config['MYSQL_DATABASE_HOST'] = config.host
....
....
....
if __name__ == '__main__':
app.run(debug=False,host='0.0.0.0')
我不明白为什么它适用于本地但未部署。
config.py肯定存在于VPS上
答案 0 :(得分:0)
重新安装Flask修复此问题。谢谢@ cricket_007