这是烧瓶python:http://pastie.org/8712899
这里是index.html模板中的html + js:http://pastie.org/8712901
问题是它在本地通过flask内置服务器运行时完全按照需要运行,但在使用apache wsgi部署时单击搜索按钮会出现500错误。
它在线(但没有功能) http://thekindlyone.scribblehead.info/calvinball/
帮助?
这里是追溯记录。
Exception on /search [GET]
Traceback (most recent call last):
File "/usr/local/lib/python2.6/dist-packages/flask/app.py", line 1817, in wsgi_app
response = self.full_dispatch_request()
File "/usr/local/lib/python2.6/dist-packages/flask/app.py", line 1477, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/usr/local/lib/python2.6/dist-packages/flask/app.py", line 1381, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/usr/local/lib/python2.6/dist-packages/flask/app.py", line 1475, in full_dispatch_request
rv = self.dispatch_request()
File "/usr/local/lib/python2.6/dist-packages/flask/app.py", line 1461, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/home/webdev/thekindlyone/calvinball/calvinball.py", line 42, in find
dbase=database('index')
File "/home/webdev/thekindlyone/calvinball/calvinball.py", line 15, in __init__
self.ix=open_dir(index_dir)
File "/usr/local/lib/python2.6/dist-packages/whoosh/index.py", line 123, in open_dir
return FileIndex(storage, schema=schema, indexname=indexname)
File "/usr/local/lib/python2.6/dist-packages/whoosh/index.py", line 421, in __init__
TOC.read(self.storage, self.indexname, schema=self._schema)
File "/usr/local/lib/python2.6/dist-packages/whoosh/index.py", line 616, in read
gen = cls._latest_generation(storage, indexname)
File "/usr/local/lib/python2.6/dist-packages/whoosh/index.py", line 593, in _latest_generation
for filename in storage:
File "/usr/local/lib/python2.6/dist-packages/whoosh/filedb/filestore.py", line 81, in __iter__
return iter(self.list())
File "/usr/local/lib/python2.6/dist-packages/whoosh/filedb/filestore.py", line 518, in list
files = os.listdir(self.folder)
OSError: [Errno 2] No such file or directory: 'index'
更新:我将whoosh索引目录路径设置为绝对路径,并将cnh.cbz路径设置为绝对路径。但即使在那之后我也得到了error。嗖的索引的东西虽然有效。是因为cnh.cbz文件在flask应用程序目录之外吗?我该如何解决? 这是新的python
from flask import Flask, jsonify, render_template, request
from whoosh.index import open_dir
from whoosh.fields import *
from whoosh.qparser import QueryParser
from whoosh import highlight
import datetime
import zipfile
import logging
app = Flask(__name__)
app.logger.addHandler(logging.FileHandler('/home/webdev/thekindlyone/flasklogs/calvinball.log'))
#yymmdd
class database(object):
def __init__(self,index_dir):
self.ix=open_dir(index_dir)
def search(self,text):
fetched=[]
brf = highlight.UppercaseFormatter()
with self.ix.searcher() as searcher:
query = QueryParser("content", self.ix.schema).parse(text)
results = searcher.search(query)
results.fragmenter=highlight.WholeFragmenter()
results.formatter = brf
for result in results:
fetched.append((result['title'],result.highlights("content")))
return fetched
def makehtml(tuples):
hypertext=''
if tuples:
for title,content in tuples:
ftitle=datetime.datetime.strptime(title[2:], '%y%m%d').strftime('%d/%m/%y')
hypertext+='''<div class="clicker" id="{0}">{1}</div><br>'''.format(title,ftitle+' '+content)
else:
hypertext='Nothing found'
return hypertext
@app.route('/search')
def find():
string = request.args.get('searchstring')
dbase=database('/home/webdev/thekindlyone/calvinball/index')
hypertext=makehtml(dbase.search(string))
return hypertext
@app.route('/')
def index():
return render_template('index.html')
@app.route('/show')
def display():
strip = request.args.get('strip')
z=zipfile.ZipFile('/home/webdev/thekindlyone/cnh.cbz')
img=z.open(strip+'.jpg')
z.close()
data_uri = img.read().encode('base64').replace('\n', '')
img_tag = '<img src="data:image/png;base64,{0}">'.format(data_uri)
return img_tag
if __name__ == '__main__':
app.run(host='0.0.0.0',debug=True)
更新2:我为cnh.cbz创建了一个到应用程序目录的硬链接,它可以运行。 但必须有更好的方法。
答案 0 :(得分:0)
基于错误,您似乎需要对whoosh db使用绝对路径名,或者至少在打开它之前适当地设置当前目录。看来Apache没有将当前目录设置为应用程序的文件夹。