Skip to content Skip to sidebar Skip to footer

Sending Flask Variable From Html Back To Flask With Url_for()

I'm trying to create a little job board, each job card is dynamically inserted from flask from a list (for now, will be an SQL DB later) When the user clicks the button View Task

Solution 1:

You generated the output href="url_for('view_task', task_id=<some id>)", so the literal text url_for(..) is in the HTML generated and delivered to your browser, and HTML engines don't recognise that string as a valid URL for anything.

You need to put the url_for() function in the {{ ... }} brackets, not just the task id value:

href="{{ url_for('view_task', task_id=task['id']) }}"

Only then is url_for() actually treated as an expression for Jinja2 to execute, at which point the HTML produces will contain the href="http://localhost:5000/view_task/<some id>" string.

Post a Comment for "Sending Flask Variable From Html Back To Flask With Url_for()"