Django variable in base.html

前端 未结 4 994
刺人心
刺人心 2020-11-30 04:35

base.html is used as the base template for all other pages. base.html has the navigation bar and in the navigation bar, I want to show the number o

4条回答
  •  猫巷女王i
    2020-11-30 05:16

    You can use tags.

    #myproject/myproject/templatetags/tags.py
    
    from django import template
    
    register = template.Library()
    
    @register.simple_tag
    def number_of_messages(request):
        return _number
    

    In your Base.html

    {% load tags %}
        {% number_of_messages request %}
    

提交回复
热议问题