第一個flask項目,做一個簡單的網(wǎng)址導航。部署項目后,瀏覽器訪問報500錯誤。查看apache日志后,報錯如下:
[Tue Jan 06 09:58:22 2015] [error] hello world
[Tue Jan 06 09:58:22 2015] [error] [client 112.64.71.131] mod_wsgi (pid=31615): Target WSGI script '/var/www/qianshan/qianshan.wsgi' cannot be loaded as Python module.
[Tue Jan 06 09:58:22 2015] [error] [client 112.64.71.131] mod_wsgi (pid=31615): Exception occurred processing WSGI script '/var/www/qianshan/qianshan.wsgi'.
[Tue Jan 06 09:58:22 2015] [error] [client 112.64.71.131] Traceback (most recent call last):
[Tue Jan 06 09:58:22 2015] [error] [client 112.64.71.131] File "/var/www/qianshan/qianshan.wsgi", line 12, in <module>
[Tue Jan 06 09:58:22 2015] [error] [client 112.64.71.131] from qianshan import app as application
[Tue Jan 06 09:58:22 2015] [error] [client 112.64.71.131] File "/var/www/qianshan/__init__.py", line 4, in <module>
[Tue Jan 06 09:58:22 2015] [error] [client 112.64.71.131] import extras
[Tue Jan 06 09:58:22 2015] [error] [client 112.64.71.131] ImportError: No module named extras
項目結(jié)構(gòu)
qianshan
├── config.ini
├── extraModules.py
├── extras.py
├── __init__.py
├── qianshan.wsgi
├── static
├── templates
├── test.py
└── venv
init.py代碼
from flask import Flask
from flask import render_template
import extraModules
import extras#如果沒有這句無報錯正常運行,只有一些靜態(tài)資源沒拉到,可能是其他問題
import ConfigParser
import codecs
import logging
logging.basicConfig(filename='qianshan.log', level=logging.INFO)
logging.info('Started')
app = Flask(__name__)
logging.info('App established')
@app.route("/")
def index():
return render_template('index.html')
extras.py是實際我想要導入的模塊,里面有兩個我需要的類;extraModules是測試模塊,import extraModules是成功的,apache日志的第一行也打出來了;他們的代碼分別如下:
extras.py
# Filename : extras.py
class Block:
def setNo(self, no):
self.no = int(no)
def getNo(self):
return self.no
def setName(self, name):
self.name = name
def getName(self):
return self.name
def setPriority(self, priority):
self.priority = int(priority)
def getPriority(self):
return self.priority
def setHotKeyAsc(self, hotKeyAsc):
self.hotKeyAsc = hotKeyAsc
def getHotKeyAsc(self):
return self.hotKeyAsc
def setElement(self, equation):
s = equation.split(':')
if(s[0] == 'no'):
self.setNo(s[1])
elif(s[0] == 'name'):
self.setName(s[1])
elif(s[0] == 'priority'):
self.setPriority(s[1])
elif(s[0] == 'hot_key_asc'):
self.setHotKeyAsc(s[1])
class Website:
def setNo(self, no):
self.no = int(no)
def getNo(self):
return self.no
def setName(self, name):
self.name = name
def getName(self):
return self.name
def setUrl(self, url):
self.url = url
def getUrl(self):
return self.url
def setIcon(self, icon):
self.icon = icon
def getIcon(self):
return self.icon
def setBlockNo(self, blockNo):
self.blockNo = int(blockNo)
def setPriority(self, priority):
self.priority = int(priority)
def getPriority(self):
return self.priority
def setHotKeyAsc(self, hotKeyAsc):
self.hotKeyAsc = hotKeyAsc
def getHotKeyAsc(self):
return self.hotKeyAsc
def setElement(self, equation):
s = equation.split(':')
if(s[0] == 'no'):
self.setNo(s[1])
elif(s[0] == 'name'):
self.setName(s[1])
elif(s[0] == 'url'):
self.setUrl(s[1])
elif(s[0] == 'icon'):
self.setIcon(s[1])
elif(s[0] == 'priority'):
self.setPriority(s[1])
elif(s[0] == 'hot_key_asc'):
self.setHotKeyAsc(s[1])
if __name__ == '__main__':
block = Block()
website = Website()
extraModules.py
# Filename : extraModules.py
print 'hello world'
其他背景信息:
項目部署在digital ocean的ubuntu12.x主機上,python版本2.7.3.
還請指導下,是不是extras.py有什么地方大意了,小弟新學python不久,請多敲打點撥
謝謝1L和2L前輩的指點??!白天一直在上課,以下為1月7日晚更新,我把wsgi以及virtual host的配置也發(fā)一下,wsgi中是有配置/var/www/qianshan/為sys.path的。
qianshan.wsgi
#!/usr/bin/python
activate_this = '/var/www/qianshan/venv/bin/activate_this.py'
execfile(activate_this, dict(__file__=activate_this))
import sys
import logging
logging.basicConfig(stream=sys.stderr)
sys.path.insert(0,'/var/www/qianshan/')
sys.path.insert(1,'/var/www/')
from qianshan import app as application
application.secret_key = 'Add your secret key'
Virtual Host配置
<VirtualHost *:80>
ServerName qianshan.co
ServerAdmin spark@qianshan.co
WSGIScriptAlias / /var/www/qianshan/qianshan.wsgi
<Directory /var/www/qianshan/>
Order allow,deny
Allow from all
</Directory>
Alias /static /var/www/qianshan/static
<Directory /var/www/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>
我會按照1L和2L的方法試試,如果不行再在這里說
添加回答
舉報
0/150
提交
取消