第一个flask项目,做一个简单的网址导航。部署项目后,浏览器访问报500错误。查看apache日志后,报错如下:[TueJan0609:58:222015][error]helloworld[TueJan0609:58:222015][error][client112.64.71.131]mod_wsgi(pid=31615):TargetWSGIscript'/var/www/qianshan/qianshan.wsgi'cannotbeloadedasPythonmodule.[TueJan0609:58:222015][error][client112.64.71.131]mod_wsgi(pid=31615):ExceptionoccurredprocessingWSGIscript'/var/www/qianshan/qianshan.wsgi'.[TueJan0609:58:222015][error][client112.64.71.131]Traceback(mostrecentcalllast):[TueJan0609:58:222015][error][client112.64.71.131]File"/var/www/qianshan/qianshan.wsgi",line12,in[TueJan0609:58:222015][error][client112.64.71.131]fromqianshanimportappasapplication[TueJan0609:58:222015][error][client112.64.71.131]File"/var/www/qianshan/__init__.py",line4,in[TueJan0609:58:222015][error][client112.64.71.131]importextras[TueJan0609:58:222015][error][client112.64.71.131]ImportError:Nomodulenamedextras项目结构qianshan├──config.ini├──extraModules.py├──extras.py├──__init__.py├──qianshan.wsgi├──static├──templates├──test.py└──venvinit.py代码fromflaskimportFlaskfromflaskimportrender_templateimportextraModulesimportextras#如果没有这句无报错正常运行,只有一些静态资源没拉到,可能是其他问题importConfigParserimportcodecsimportlogginglogging.basicConfig(filename='qianshan.log',level=logging.INFO)logging.info('Started')app=Flask(__name__)logging.info('Appestablished')@app.route("/")defindex():returnrender_template('index.html')extras.py是实际我想要导入的模块,里面有两个我需要的类;extraModules是测试模块,importextraModules是成功的,apache日志的第一行也打出来了;他们的代码分别如下:extras.py#Filename:extras.pyclassBlock:defsetNo(self,no):self.no=int(no)defgetNo(self):returnself.nodefsetName(self,name):self.name=namedefgetName(self):returnself.namedefsetPriority(self,priority):self.priority=int(priority)defgetPriority(self):returnself.prioritydefsetHotKeyAsc(self,hotKeyAsc):self.hotKeyAsc=hotKeyAscdefgetHotKeyAsc(self):returnself.hotKeyAscdefsetElement(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])classWebsite:defsetNo(self,no):self.no=int(no)defgetNo(self):returnself.nodefsetName(self,name):self.name=namedefgetName(self):returnself.namedefsetUrl(self,url):self.url=urldefgetUrl(self):returnself.urldefsetIcon(self,icon):self.icon=icondefgetIcon(self):returnself.icondefsetBlockNo(self,blockNo):self.blockNo=int(blockNo)defsetPriority(self,priority):self.priority=int(priority)defgetPriority(self):returnself.prioritydefsetHotKeyAsc(self,hotKeyAsc):self.hotKeyAsc=hotKeyAscdefgetHotKeyAsc(self):returnself.hotKeyAscdefsetElement(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.pyprint'helloworld'其他背景信息:项目部署在digitalocean的ubuntu12.x主机上,python版本2.7.3.还请指导下,是不是extras.py有什么地方大意了,小弟新学python不久,请多敲打点拨谢谢1L和2L前辈的指点啊!白天一直在上课,以下为1月7日晚更新,我把wsgi以及virtualhost的配置也发一下,wsgi中是有配置/var/www/qianshan/为sys.path的。qianshan.wsgi#!/usr/bin/pythonactivate_this='/var/www/qianshan/venv/bin/activate_this.py'execfile(activate_this,dict(__file__=activate_this))importsysimportlogginglogging.basicConfig(stream=sys.stderr)sys.path.insert(0,'/var/www/qianshan/')sys.path.insert(1,'/var/www/')fromqianshanimportappasapplicationapplication.secret_key='Addyoursecretkey'VirtualHost配置ServerNameqianshan.coServerAdminspark@qianshan.coWSGIScriptAlias//var/www/qianshan/qianshan.wsgiOrderallow,denyAllowfromallAlias/static/var/www/qianshan/staticOrderallow,denyAllowfromallErrorLog${APACHE_LOG_DIR}/error.logLogLevelwarnCustomLog${APACHE_LOG_DIR}/access.logcombined我会按照1L和2L的方法试试,如果不行再在这里说
添加回答
举报
0/150
提交
取消