Using the 'user' condition in custom links

298 views
Skip to first unread message

Benjamin Boussereau

unread,
Oct 16, 2020, 7:54:41 AM10/16/20
to NetBox
Hi everyone,
I'm new in netbox and i want to create a custom link that will appear only if the user is the one named admin.
I've tried using the command "{% if user == 'admin' %} but it doesn't work.
When i try to use the following one : "{% if user.name == 'admin' %} it says that the 'user' is undefined.
Is there an issue in the lastest version of netbox where the "user" condition is not availbale anymore (in the doc it says that it is availbale).

Thanks in advance for your reply.

Best regards,

Jeremy Stretch

unread,
Oct 16, 2020, 9:06:31 AM10/16/20
to Benjamin Boussereau, NetBox
The user's name is referenced as {{ user.username }} ("username" is the name of the field on the model).

FYI in the future if you need a quick and dirty way to check available attributes, you can put {{ foo.__dict__() }} in a Jinja2 template to print them out.

--
You received this message because you are subscribed to the Google Groups "NetBox" group.
To unsubscribe from this group and stop receiving emails from it, send an email to netbox-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/netbox-discuss/9f1c257b-e162-430b-a0ca-cc5ad88f2df2n%40googlegroups.com.


--
Jeremy Stretch
Sr. Network Automation Engineer
Network to Code, LLC

Armin Bube

unread,
Feb 2, 2021, 7:48:00 AM2/2/21
to NetBox
I would like to see all available attributes to work something out with custom links but a {{ obj.__dict__() }} is just returning a "'dict' object is not callable". Does anyone has an idea how to get a list of available attributes?

Best regards,
 Armin

Jacob Young US

unread,
Feb 12, 2021, 5:49:01 PM2/12/21
to NetBox
Hey Armin,  I'm sure Jeremy means {{ obj.__dict__ }} (no parenthesis).

I'm having trouble using the {{ user.username }} as well.  The link actually becomes greyed out and has a warning triangle icon if I try to access {{ user.username }} 

bad_link.jpg

Where if I just put a bogus attribute on the obj value like "User {{ obj.doesntexist }}" I get the regular link:

good_link.jpg

I'm using Netbox v2.8.9

Jacob

Jacob Young

unread,
Feb 12, 2021, 6:13:17 PM2/12/21
to NetBox
Nevermind.  It looks like accessing data other than 'obj' in custom links wasn't added until v2.9.5

Jacob

Reply all
Reply to author
Forward
0 new messages