Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django Templates and MongoDB _id

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

How does one reference the _id of an item gotten from MongoDB in Django Templates?

like image 679
user3467349 Avatar asked Jul 24 '14 14:07

user3467349


People also ask

Does Django work well with MongoDB?

Django, the most popular Python web framework, is an ideal tool to build secure and easy-to-maintain applications using MongoDB. Using MongoDB with Django is advantageous because: Every second, more and more unstructured data is generated from various sources like chats, real-time streams, feeds, and surveys.


1 Answers

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' }}
like image 92
alecxe Avatar answered Sep 19 '22 02:09

alecxe