Passing HTML tag data- to Django with form submit

I am trying to pass data in HTML tag with a form submit to Django

I currently have a template like this:

{% for item in items %}
    <div class="product">
        {{ item.item_name }}
            <form method="POST">
                {% csrf_token %}
                    value="add to cart"
{% endfor %}

I want to pass data-pk with a Django form. How do I do that? Also I know, I can create a view to handle endpoint to do that, and include pk in the url, is that a better solution?

I am new to Django, and I will be grateful for any input on how to do stuff the right way

Instead of data, use value={{}} and handle the submit logic in your view.

Back to Top