I'm building a test Flask app where the end user can select the sql parameters that are passed to a python script. I've had no problems passing queries for text fields, but the date range is giving me trouble. I've tried implementing strftime() but I must have used it incorrectly (AttributeError: 'str' object has no attribute 'strftime').
When I remove strftime() I get the following error: "RuntimeError: An invalid SQL statement was used". The user is selecting a mm/dd/yyyy from the calendar popup for date_before and date_after. I'm not experienced with this stuff and am just cobbling things together to see what works. I'll include snippets of my app.py and export.py files if anyone has suggestions
Updated to include the html tags
@app.route('/', methods=['POST'])
def export_data_route():
type_query = request.form['type_query']
leader_query = request.form['leader_query']
assigned_query = request.form['assigned_query']
date_after = request.form['date_after']
date_before = request.form['date_before']
export_data(type_query, leader_query, assigned_query, date_after, date_before)
def export_data(type_query, leader_query, assigned_query, date_before, date_after):
# Fetch data using arcpy and convert to pandas DataFrame
workorders_fields = [field.name for field in arcpy.ListFields(f'{gdb_path}\\{workorders_fc}')]
staff_fields = [field.name for field in arcpy.ListFields(f'{gdb_path}\\{staff_rt}')]
print("Converting to pandas DataFrame")
# Fetch data from both tables
workorders_data = []
with arcpy.da.SearchCursor(f'{gdb_path}\\{workorders_fc}', workorders_fields, where_clause=f"Type = '{type_query}' AND teamLeader = '{leader_query}' AND teamAssigned = '{assigned_query}' AND dateReceived <= '{date_before}' AND dateReceived >= '{date_after}'") as cursor:
for row in cursor:
workorders_data.append(row) <label for="date_before">Date Before:</label>
<input type="date" id="date_before" name="date_before"><br><br>
<label for="date_after">Date After:</label>
<input type="date" id="date_after" name="date_after"><br><br>