Answer the question
In order to leave comments, you need to log in
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>
class Sample(models.Model):
......
def obj_del(self):
super(Sample, self).delete(*args, **kwargs)
Answer the question
In order to leave comments, you need to log in
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 questionAsk a Question
731 491 924 answers to any question