-1

I have a python script (display_names.py) that displays the list of names in the json file

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())

I am trying to call this function in my html file(crawl.html) using flask.

{% 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 %}

My routes file is as follows:

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()

This doesnt work and it always gives an error on the html page please help

dipit
  • 105
  • 2
  • 5
  • 8
  • this might be of help. http://stackoverflow.com/questions/11590084/calling-python-functions-in-html-file-in-flask – Buddha_Peace Nov 24 '14 at 17:51
  • not really . i am not concerned with the folder. I just want to call the function of that python program in my html page – dipit Nov 24 '14 at 18:00

1 Answers1

0

I believe you need to execute the function when calling it. In python, to execute a function, you use parentheses, so try:

{{ myfucntion() }}

Edit: I see you typoed them both, so that was not an issue. My apologies.

sejje
  • 99
  • 1
  • 1
  • 5
  • what can be done to call that function. Moreover how can it call a function from another script without importing it – dipit Nov 24 '14 at 17:48