L
L
lukepker2019-08-03 20:37:34
Django
lukepker, 2019-08-03 20:37:34

How to pass value on button click in Django?

Hello, I have this code:

<div class="container mb-5">
            <div class="row">
                {% for item in jumbo.section.articles.all %}
                    <div class="col-md-4">
                        <h2>{{ item.title }}</h2>

                        <a href="{% url 'item' %}?id={{ item.id }}">

                          <img src="{{ MEDIA_URL }}{{ item.image.url }}" width="180">

                        </a>

                        <form>
                          <input type="submit" class="btn btn-secondary" value="Добавить в корзину »">
                        </form>
                    </div>
                {% endfor %}
            </div>
        </div>

I need the item.id on which it is clicked to be transmitted when clicking on the button (and then in the view, do something with it, how to implement it?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
W
Web Dentist, 2019-08-03
@lukepker

Hello. Alternatively, make the input hidden withvalue="{{item.id}}"

J
JRazor, 2019-08-03
@JRazor

Oh, well, here you need to read about forms in HTML and forms in Django. Other and do not recommend

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question