S
S
SashaN692021-01-13 19:40:02
Django
SashaN69, 2021-01-13 19:40:02

How to call a python function on button click in Django?

Is it possible to somehow call a python function in Django on button click?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Poul00, 2021-01-13
@SashaN69

Yes, it is possible. You can do this by giving the button a route, so after clicking it, the function associated with this route will open.
For example, on the main page there is a like button: After clicking, the route will open:
<a href="{% url 'score' track.pk %}">Like</a>

path('scoring/<str:pk>', like_or_dislike, name='score'),

And the function associated with this route will be called, but then the page will be updated when the button is clicked, you can avoid this using the Django REST Framework https://www.django-rest-framework.org

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question