Repository navigation
Referencing the custom object type in a template #638
|
I'm regularly using this kind of syntax in templates of my own plugins: where the link URL renders as How to do the same with custom object types? I haven't found a working syntax. For example this: (where It leads to error: What would be the correct way to get a link to a custom object type instance in a template? |
Replies: 2 comments 1 reply
|
Other syntaxes tested with same error:
|
|
The reason Simplest: use
|
The reason
dns_zonefails is that the plugin doesn't register a URL per custom object type — there's nodns_zoneview. All custom objects are served by a single generic view namedcustomobject, so{% url 'plugins:netbox_custom_objects:dns_zone' ... %}can never reverse (henceReverse for 'dns_zone' not found).Simplest: use
get_absolute_urlCustom objects implement it, so you don't need
{% url %}at all:That's the same pattern NetBox core uses, and it's the most robust because the plugin owns the reverse logic. From the model (
netbox_custom_objects/models.py):