I am working on a flask app that will take a user input from a form and pass it on to the Todosit API to generate a task. I have been able to authenticate and verify the API version of the code is working, my only hangup now seems to be getting the data from the front end (jinja template) passed in as a variable to the Todoist API POST call.
Here is my Python code for the route:
@app.route('/', methods=['GET', 'POST'])
def home():
if request.form["submit"] == "submit":
task = request.form["task"]
due_date = request.form["dueDate"]
requests.post(
"https://api.todoist.com/rest/v1/tasks",
data=json.dumps({
"content": task,
"label_ids": [2154915513],
"due_string": due_date,
"due_lang": "en",
"priority": 1
}),
headers={
"Content-Type": "application/json",
"X-Request-Id": str(uuid.uuid4()),
"Authorization": f"Bearer {API_KEY}"
}).json()
Here is the HTML form code:
<form>
<label for="task">Enter Task:</label><br>
<input type="text" id="task" name="task"><br>
<label for="due_date">Enter Due Date (Leave Blank if None):</label><br>
<input type="text" id="due_date" name="due_date">
<input type="submit" value="Submit">
</form>
When I run this and add a task & due date, the results are not passed into the variables task
& due date
correctly. Does anyone have any advice on passing front end variables to the Flask route for processing? Thanks!