Hi all I am trying to get an app to work and i keep on getting an error

jinja2.exceptions.UndefinedError jinja2.exceptions.UndefinedError: 'data' is undefined

here is my code it would be great is someone would be able to help

import ipapi
from flask import Flask, request, render_template
from flaskext.mysql import MySQL

# import geocoder

mysql = MySQL()
app = Flask(__name__)
app.config['MYSQL_DATABASE_USER'] = ''
app.config['MYSQL_DATABASE_PASSWORD'] = '@04012014'
app.config['MYSQL_DATABASE_DB'] = 'nobis'
app.config['MYSQL_DATABASE_HOST'] = 'localhost'

def my_form():
return render_template('text.html')

@app.route("/", methods=['POST'])
def Authenticate():
search = request.form['si']
cursor = mysql.connect().cursor()
cursor.execute("SELECT * from Companys where B_Type like '" + "%" + search + "%" + "'")
data = cursor.fetchall()
return render_template('results.html', data=data)

@app.route("/", methods=['POST'])
def my_form_post():
text = request.form['si']
processed_text = text.upper()

return processed_text

@app.route("/search", methods=["POST", "GET"])
def search():
return render_template("search.html")

@app.route("/New_CLient", methods=["POST", "GET"])
def newclient():
return render_template("New_CLient.html")

@app.route('/location', methods=['GET', 'POST'])
def Index():
searchl = request.form.get('search')
data = ipapi.location(ip=searchl, output='json')
return render_template('text.html', data=data)

if __name__ == "__main__":
  • The error message comes from an html that is trying to perform a python action on a variable named data which is undefined. Speculation would indicate "text.html" since that is called in two places, one with a data argument and one without. Dec 23 '20 at 12:56

You must log in to answer this question.

Browse other questions tagged .