-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

2
  • this might be of help. stackoverflow.com/questions/11590084/… Commented Nov 24, 2014 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 Commented Nov 24, 2014 at 18:00

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

what can be done to call that function. Moreover how can it call a function from another script without importing it

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.