3

view.py

class test(ListView):
    model = TestModel
    template_name = 'test/test.html'
    context_object_name = 'test'

    def myfunc(self):
        return 'test'

Как вывести в шаблон html функцию myfunc?
{{ myfunc }} и {{ test.myfunc }} не работает...

2

1 ответ 1

0

задачу решил, кому может пригодится

views.py

 class TestView(ListView):
        model = Test
        template_name = 'test/test.html'
        context_object_name = 'test'   
        
        def get_context_data(self, *, object_list=None, **kwargs):
            context = super().get_context_data(**kwargs)
            context['test_data']= 'some data'
            return context

test_tags.py

register = template.Library()
@register.inclusion_tag('test/test_tags.html')
def install_plugin(arg1='empty'):
    #some work...
    return {'data' : arg1}

test_tags.html

{{ data }}

test.html

{% test_tags test_data %}

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.