[Fixed]-Django : How to give parameters to {% url %} tag in javascript function which will be used in FOR loop?

1👍

I fixed it with input javascript code to the onclick attribute like

<b><button onclick="location.href='{% url 'photo:album_edit' item.id %}'">Edit</button></b>

0👍

You can pass a parameter in your js onclick function:

<button onclick="albumEdit({{ url 'photo:album_edit' item.id }})">Edit</button>

and use it to make the redirection:

function albumEdit(href_url){
    location.href=href_url;
}
👤XaviP

Leave a comment