Skip to content

How can I get the full/absolute URL of NetBox instance within a NetBox script? #7054

Answered by candlerb
drygdryg asked this question in Q&A
Discussion options

You must be logged in to vote

In general, your Netbox instance may be accessed via many URLs which all resolve to the same host.

Hence you probably want to look at the Request object to see how the user is currently accessing it:
https://netbox.readthedocs.io/en/stable/additional-features/custom-scripts/#accessing-request-data

Look at how the SVG code creates an absolute base URL:
https://github.com/netbox-community/netbox/blob/v2.11.12/netbox/dcim/api/views.py#L216

Or you may be able to use the django 'reverse' method:
https://github.com/netbox-community/netbox/blob/v2.11.12/netbox/dcim/models/devices.py#L643-L644

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by drygdryg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants