Django and MongoDB _id Templates

Variables and attributes may not begin with underscores: 'value._id'

How does it refer to an _idelement derived from MongoDB in Django templates?

+4
source share
1 answer

A custom template filter will help:

from django import template

register = template.Library()

@register.filter(name='private')
def private(obj, attribute):
    return getattr(obj, attribute)

You can use it as follows:

{{ value|private:'_id' }}
+9
source

All Articles