2014-11-24 2 views
-2

HTML 페이지에서 파이썬 함수를 호출 할 수 없습니다 내 html 파일에서이 함수를 호출하는 것을 시도하고있다JSON 파일에 이름 목록을 표시하는 내가 파이썬 스크립트 (display_names.py)가

def search(): 
    with open('business_ten.json') as f: 
     data=f.read() 
     jsondata=json.loads(data) 
     for row in jsondata['rows']: 
      a=str(row['name']) 
      yield a 

print list(search()) 

(crawl.html) 플라스크를 사용하십시오.

from flask import Flask,render_template 
app = Flask(__name__) 

@app.route('/') 
def hello_world(): 
    return 'Hello World!' 
@app.route('/crawl') 
def crawl(): 
    return render_template('crawl.html' , myfucntion=search) 
if __name__ == '__main__': 
    app.run() 

이 나던 일을하고 항상 이

+0

도움이 될 수 있습니다. http://stackoverflow.com/questions/11590084/calling-python-functions-in-html-file-in-flask –

+0

아니요. 나는 그 폴더에 관심이 없다. 난 그냥 내 HTML 페이지에서 그 파이썬 프로그램의 기능을 호출하고 싶습니다 – dipit

답변

0

도와주세요 HTML 페이지에 오류 난 당신이 때의 기능을 실행해야 생각을 제공 : 다음과 같이

{% extends "layout.html" %} 
{% block content %} 
<div class="jumbo"> 
<h2>Welcome to the Rating app<h2> 
<h3>This is the home page for the Rating app<h3> 
</div> 
<body> 
    <p>{{ myfucntion}}</p> 
    </body> 
{% endblock %} 

내 경로 파일입니다 그것을 부른다. 파이썬에서, 괄호를 사용하여 기능을 실행, 그래서 시도 :

{{ myfucntion() }} 

편집 : 나는 그 문제가 아니었다 있도록, 둘 다 typoed 참조하십시오. 내 사과.

+0

그 기능을 호출 할 수 있습니다. 또한 다른 스크립트에서 함수를 가져 오지 않고 어떻게 호출 할 수 있습니까? – dipit

관련 문제