Python Forum
how to pass javascript variables to url_for function in a flask template
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to pass javascript variables to url_for function in a flask template
#1
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
Reply
#2
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.
Reply
#3
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?
Reply
#4
nobody knows...
Reply
#5
solved...
Reply
#6
(May-09-2020, 04:56 PM)experimental Wrote: solved...

how to solve this problem?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  IndexError: list index out of range" & "TypeError: The view function f: Flask Web App joelbeater992 5 556 Aug-31-2021, 08:08 PM
Last Post: joelbeater992
  show csv file in flask template.html rr28rizal 8 27,622 Apr-12-2021, 09:24 AM
Last Post: adamabusamra
Thumbs Up Flask do not accept sub-folder in Template ?! : Solved SpongeB0B 2 798 Jan-15-2021, 08:09 AM
Last Post: ndc85430
  how to create dynamic arguments to be passed in jinja template in url_for function? experimental 1 1,160 May-01-2020, 05:50 PM
Last Post: Larz60+
  Flask Create global response function to be called from every where in the web app umen 2 902 Apr-14-2020, 09:54 PM
Last Post: umen
  flask-SQLAlchemy query with keyword as function argument pascale 2 1,920 Mar-13-2019, 08:45 PM
Last Post: Ecniv
  How to capture value from javascript using flask Prince_Bhatia 0 1,400 Nov-02-2018, 10:20 AM
Last Post: Prince_Bhatia
  Uploading multiple pdfs to Flask ( Sql alchmey) with additional variables KirkmanJ 10 6,098 Jul-27-2018, 09:49 AM
Last Post: KirkmanJ
  Django - Passing data from view for use client side with JavaScript in a template bountyhuntr 0 2,311 Jun-11-2018, 06:04 AM
Last Post: bountyhuntr
  unable to call function in Flask verb 5 13,238 Sep-29-2016, 02:27 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020