2014-02-08 9 views
0
여기

플라스크 파이썬입니다 플라스크 : http://pastie.org/8712901오류 500 JQuery와 아약스 얻을

문제는 정확히 같은 싶었던 작품이다 : http://pastie.org/8712899

여기에 index.html을 템플릿의 HTML + JS입니다 플라스크 inbuilt 서버를 통해 로컬로 실행하지만 아파치 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' 

업데이트 : 절대에 붕 인덱스 디렉토리 경로도 절대에 cnh.cbz 경로를 설정합니다. 하지만 그 후에도 error이 나옵니다. 그러나 whoosh 색인은 작동합니다. cnh.cbz 파일이 플라스크 응용 프로그램 디렉토리 외부에 있기 때문입니까? 이 문제를 어떻게 해결할 수 있습니까? 여기에 새로운 파이썬

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에 대한 하드 링크를 생성하고 그것을 작동합니다. 그러나 더 좋은 방법이 있어야합니다.

+1

아파치 기반 서버의 로그 파일에 스택 추적을 보내도록 구성하면 500 오류가 발생했을 때 눈이 멀지 않습니다. 오류의 의미를 이해할 수 없다면 질문과 함께 스택 추적을 추가하십시오. – Miguel

+0

@Miguel 나는 할 수 없다. [This] (http://pastie.org/8714023)는 로그하려고 할 때 일어납니다. – thekindlyone

답변

0

오류에 따라 whoosh db에 대한 절대 경로 이름을 사용하거나 적어도 현재 디렉토리를 적절하게 설정해야합니다. 아파치가 현재 디렉토리를 애플리케이션의 폴더로 설정하지 않은 것처럼 보입니다.

+0

나는 whoosh db와 cnh.cbz zip 파일의 절대 경로를 설정했다. whoosh 물건은 절대 디렉토리와 함께 작동합니다. zip 파일은 그렇지 않습니다. [추적] (http://pastie.org/8714154) – thekindlyone