I have a Flask app which will execute another python script in the background and fetch data from the database to be displayed to the user. The script fails as it cannot initialize the local variables.
FetchAPI.py
import FetchDataFor_P_NAME as fetch
from flask import Flask
app = Flask(__name__)
@app.route('/batch21')
def fetchBatch21Data():
return fetch.main()
if __name__ == '__main__':
app.run()
FetchDataFor_P_NAME.py
def main():
'''some statements to fetch data using the start_date'''
query = query.replace('?', "'" + start_date + "'")
if __name__ == '__main__':
'''some statements'''
start_date = '01-JAN-14 00:00'
main()
Whenever I execute the Flask app and call the page /batch21 I get the following error:
query = query.replace('?', "'" + start_date + "'")
NameError: name 'start_date' is not defined
This is my first time working with an API in Python. I am not sure what I am missing here.