[Django]-Function with arguments in a template. Django

5👍

It looks as though you are confusing client-side code (JavaScript) with server-side (Django).

To get the relevant user ID submitted you could add an additional hidden field to the form:

{% for user in following % }
<form method="post" action="{% url views.remove_relationship %}">
 {% csrf_token %}
<input type="hidden" name="user_id" value="{{ user.id }}">
<input type="submit" value="delete" />
</form>
{%endfor%}

Then create a remove_relationship view that does the deletion on the server side, based on the user id you’ll now find in request.POST['user_id']

Leave a comment