Skip to content
Advertisement

Implementing JS in Django templates

I have a list of ingredients, for every ingredient, I would like to give the option to delete the current ingredient via using a popup that asks the user “are you sure they want to delete this?” If confirmed, I want that ingredient to be deleted. Currently, no matter which ingredient I choose to delete, it always the deletes the first ingredient in the list. For example, if the list of ingredients is [‘cheese’, ‘lettuce’], I click remove ingredient under lettuce, and it will still delete cheese. I’ve never used javascript in Django templates before, I think I need to pass the ingredient into the openPopup function, but I’m not sure how to do it, any help would be appreciated! I’ve looked at the Django docs for using JS in templates but it’s not crystal clear to me. How do I go about doing this?

JavaScript

Advertisement

Answer

I think you need to pass the url to delete a specific ingredient to the js function and then change the form action accordingly, something like:

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement