how to pass javascript variables to url_for function in a flask template - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Web Scraping & Web Development (https://python-forum.io/forum-13.html) +--- Thread: how to pass javascript variables to url_for function in a flask template (/thread-26453.html) |
how to pass javascript variables to url_for function in a flask template - experimental - May-02-2020 i need to dynamically generate parameters for url after clicking on <a href> link. having jinja code like this: {% for i in data %} <a href='{{url_for("play", artist="???", album="???", title="???" )}}' onclick='clickfunc(link)'>{{ i }}</a> <br> {% endfor %}how do i pass javascript variables for artist, album, title (on the place where are the question marks). this is my js function function clickfunc(link) { var t = link.innerText || link.textContent; var splitted = t.split(" - ") artist = splitted[0] album = splitted[1] title = splitted[2] return [artist, album, title]; }is there a way to do it? so far i havent found any answer that would help RE: how to pass javascript variables to url_for function in a flask template - ndc85430 - May-02-2020 I'm not really understanding what you want to do. Why do you need to do anything client-side at all? Why not just build the links appropriately on the server (i.e. in the template, or wherever else you're doing it)? Please explain more. RE: how to pass javascript variables to url_for function in a flask template - experimental - May-02-2020 This is actually what i wrote in my previous question. I am creating an online player and here I have a search box which returns songs from a databases that matches the search string searched https://prnt.sc/s9avwl. Each line is clickable and each contains info about the artist name, album name, and song name. What I want to do now is, that after clicking it will redirect me to specific url like this .../artistname/albumname/titlename where artistname albumname titlename will be different based on what was clicked. So if i click the first one it should be steveroach/possibleplanet/firstmurmer second should be steveroach/possibleplanet/cellmemory etc.. But i dont now how to create these dynamic arguments to be passed in jinja template in url_for function... How do i get the values of the clicked linked? I need to somehow interact with the fronend code i believe. Or how should i solve it? RE: how to pass javascript variables to url_for function in a flask template - experimental - May-05-2020 nobody knows... RE: how to pass javascript variables to url_for function in a flask template - experimental - May-09-2020 solved... RE: how to pass javascript variables to url_for function in a flask template - universe - Oct-29-2020 (May-09-2020, 04:56 PM)experimental Wrote: solved... how to solve this problem? |