Django Template Tags in Views

前端 未结 4 1456
被撕碎了的回忆
被撕碎了的回忆 2020-12-29 12:47

Hi I need to refresh my custom template tag --right_side.py-- via Ajax. Is there a way to import the template tag in the view and return it as HttpResponse because I don\'t

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-29 13:02

    I found this solution :

    from templatetags_file_name import my_templatetag
    return render (request,'path/to/template.html', my_templatetag(parameter) )
    

    And, in my "templatetags_file_name", "my_templatetag" is like that :

    @register.inclusion_tag('path/to/template.html') 
    def my_templatetag(parameter):
        #my operations
        return locals()
    

提交回复
热议问题