J
J
Jekson2019-07-10 13:22:36
Django
Jekson, 2019-07-10 13:22:36

How to use class methods in Django template?

Is it possible to call methods defined in the class in html templates? For example, I want to send a request to delete an instance from the front. I can write a view, url under it and call it in the form in the template.
like this

<form action="{% url 'obj_dell' %}" method="post">
                              {% csrf_token %}                            
                              <input type="hidden" name="pk" value="{{ obj.pk }}">
                              <input type="submit" value="Удалить">
</form>

And if we define in the model
class Sample(models.Model):
    ......
    def obj_del(self):
        super(Sample, self).delete(*args, **kwargs)

Is there a way to pass this into the template?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
alternativshik, 2019-07-10
@Lepilov

requests are handled by the view. From it and call after checking for authorization and other things, your model method.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question