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 >
{{ item.item_name }}
<form method="POST">
{% csrf_token %}
<input
type="submit"
value="add to cart"
data-pk="{{item.pk}}"
/>
<form>
</div>
{% 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
CodePudding user response:
Instead of data
, use value={{item.pk}}
and handle the submit logic in your view.