I have two functions in flask I am not really sure if this is good approach or not ? First one is template renderer
@app.route('/displayreports')
def display_report():
return render_template('Displayreports.html', reports=reports)
Second one is api function to update the data called from html by button. I want to store function_last_used_date value in server side to show it later at display report. Is there anyway to store it outside a function without calling it ?
@app.route('/displayreports/data')
def api_get_reports():
import datetime
function_last_used_date = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
get_reports()
return {'reports': list(reports), 'last_updated_date': updated_date}
You probably want to store the variable datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
Flask Session saves data specific to a browser session initiated by a user and eliminates the need for global variables.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.