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 %}

Ваш ответ

Нажимая на кнопку «Отправить ответ», вы соглашаетесь с нашими пользовательским соглашением, политикой конфиденциальности и политикой о куки

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