Django Templates and MongoDB _id

后端 未结 1 1028
花落未央
花落未央 2021-01-19 03:09
Variables and attributes may not begin with underscores: \'value._id\'

How does one reference the _id of an item gotten from MongoDB i

相关标签:
1条回答
  • 2021-01-19 03:54

    Custom template filter would help:

    from django import template
    
    register = template.Library()
    
    @register.filter(name='private')
    def private(obj, attribute):
        return getattr(obj, attribute)
    

    You can use it this way:

    {{ value|private:'_id' }}
    
    0 讨论(0)
提交回复
热议问题