# How can code be activated on click of a button in a Django view?

**URL:** <https://forum.djangoproject.com/t/how-can-code-be-activated-on-click-of-a-button-in-a-django-view/18854>\
**Category:** Getting Started\
**Created:** [February 15, 2023, 12:17pm UTC](https://forum.djangoproject.com/t/how-can-code-be-activated-on-click-of-a-button-in-a-django-view/18854 "2023-02-15T12:17:31Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![k8004kv](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/k8004kv/32/12148_2.png) [@k8004kv](https://forum.djangoproject.com/u/k8004kv)\
**Post date:** [February 15, 2023, 12:17pm UTC](https://forum.djangoproject.com/t/how-can-code-be-activated-on-click-of-a-button-in-a-django-view/18854/1 "2023-02-15T12:17:31Z")

</div>

I have a template that contains a button.

I have a view for this template in a view file.

How can a part of the code be activated when this button is clicked - which is in the template?

How can you make this as easy as possible?

How can code be activated on click of a button in a Django view?

```auto
def click_button_summ(request):
    context = {}
    if request.POST.get("button_table_summ") == "button_table_summ":
        ///code///
    return render(request, "click_button_summ.html", context)

    <div class="ui container">
        <div class="column">
            <button type="submit" class="ui button" name="button_table_summ" value="button_table_summ">Button</button>
        </div>
    </div>`

```

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [February 15, 2023, 1:31pm UTC](https://forum.djangoproject.com/t/how-can-code-be-activated-on-click-of-a-button-in-a-django-view/18854/2 "2023-02-15T13:31:27Z")

</div>

Buttons aren’t clicked in a Django view. Buttons are clicked on a web page.

That click can cause the button to issue an http request.

The url in that request is looked up in the urls.py files to find the appropriate view.

The view is called with the request as a parameter.

The view returns a response.

The browser is responsible for handling that response.

So any html that results in the generation of a request will work for you. It’s then more of a question of what you want the response to be, and how the browser is going to handle it. (For example, what problems might be caused by a user clicking the button twice in a row?)
