Hardcoded paths #159

Closed
opened 2025-12-29 15:35:32 +01:00 by adam · 7 comments
Owner

Originally created by @Gelob on GitHub (Jul 6, 2016).

Their are paths that are hardcoded in various files, this means if you want to run netbox in a subdirectory on an existing webserver you have to manually edit a lot of files.

Originally created by @Gelob on GitHub (Jul 6, 2016). Their are paths that are hardcoded in various files, this means if you want to run netbox in a subdirectory on an existing webserver you have to manually edit a lot of files.
adam added the type: bug label 2025-12-29 15:35:32 +01:00
adam closed this issue 2025-12-29 15:35:32 +01:00
Author
Owner

@mdlayher commented on GitHub (Jul 6, 2016):

To clarify, do you want to allow the root of the API to be specified via config? So if you set the root as /netbox/, an API call would be something like /netbox/api/ipam/vlans?

@mdlayher commented on GitHub (Jul 6, 2016): To clarify, do you want to allow the root of the API to be specified via config? So if you set the root as `/netbox/`, an API call would be something like `/netbox/api/ipam/vlans`?
Author
Owner

@Gelob commented on GitHub (Jul 6, 2016):

@mdlayher The goal would be to be able to run netbox in a subdirectory and also have that subdirectory be named whatever we want. The hardcoded /api/ paths are a good example where this is an issue. We are currently doing this and I've included a diff of all the files we had to edit. I've had to edit out some other changes so the diff line numbers are not 100% accurate.

https://gist.github.com/Gelob/0914c3ee5219b70e63d15b2b70b9d9bc

My thought would be to have a variable in configuration.py to specify the path like BASE_URL but there may be better ways to handle this with Django or abstract it out so you don't have to specify.

@Gelob commented on GitHub (Jul 6, 2016): @mdlayher The goal would be to be able to run netbox in a subdirectory and also have that subdirectory be named whatever we want. The hardcoded /api/ paths are a good example where this is an issue. We are currently doing this and I've included a diff of all the files we had to edit. I've had to edit out some other changes so the diff line numbers are not 100% accurate. https://gist.github.com/Gelob/0914c3ee5219b70e63d15b2b70b9d9bc My thought would be to have a variable in configuration.py to specify the path like BASE_URL but there may be better ways to handle this with Django or abstract it out so you don't have to specify.
Author
Owner

@mdlayher commented on GitHub (Jul 6, 2016):

Seems reasonable to me to have a base path like that prepended to NetBox paths, via a configuration option.

@mdlayher commented on GitHub (Jul 6, 2016): Seems reasonable to me to have a base path like that prepended to NetBox paths, via a configuration option.
Author
Owner

@Gelob commented on GitHub (Jul 20, 2016):

The upgrade.sh script should also detect the directory it is in and not hardcode paths

@Gelob commented on GitHub (Jul 20, 2016): The upgrade.sh script should also detect the directory it is in and not hardcode paths
Author
Owner

@iamdadmin commented on GitHub (Aug 31, 2016):

Could we maybe get this roadmapped for 1.6? It's only a few variables which need to reference BASE_DN being either / or /netbox or /whatever_I_chose.

@iamdadmin commented on GitHub (Aug 31, 2016): Could we maybe get this roadmapped for 1.6? It's only a few variables which need to reference BASE_DN being either / or /netbox or /whatever_I_chose.
Author
Owner

@iamdadmin commented on GitHub (Sep 1, 2016):

Found a few more files with hardcoded paths for the API - the below prevent the 'Mark Connected' buttons from working.

netbox/templates/dcim/device.html: return toggleConnection($(this), "/api/dcim/console-ports/");
netbox/templates/dcim/device.html: return toggleConnection($(this), "/api/dcim/power-ports/");
netbox/templates/dcim/device.html: return toggleConnection($(this), "/api/dcim/interface-connections/");

And also in netbox/templates/_base.html you need to change this

            <a class="navbar-brand" href="/">
                <img src="{% static 'img/netbox_logo.png' %}" />
            </a>

To this (adjust for your subdirectory as needed) if you want the logo to redirect you to the location

            <a class="navbar-brand" href="/netbox">
                <img src="{% static 'img/netbox_logo.png' %}" />
            </a>

Of course, all this just replaces all the hardcoded paths with new ones.

@iamdadmin commented on GitHub (Sep 1, 2016): Found a few more files with hardcoded paths for the API - the below prevent the 'Mark Connected' buttons from working. > netbox/templates/dcim/device.html: return toggleConnection($(this), "/api/dcim/console-ports/"); > netbox/templates/dcim/device.html: return toggleConnection($(this), "/api/dcim/power-ports/"); > netbox/templates/dcim/device.html: return toggleConnection($(this), "/api/dcim/interface-connections/"); And also in netbox/templates/_base.html you need to change this > ``` > <a class="navbar-brand" href="/"> > <img src="{% static 'img/netbox_logo.png' %}" /> > </a> > ``` To this (adjust for your subdirectory as needed) if you want the logo to redirect you to the location > ``` > <a class="navbar-brand" href="/netbox"> > <img src="{% static 'img/netbox_logo.png' %}" /> > </a> > ``` Of course, all this just replaces all the hardcoded paths with new ones.
Author
Owner

@jeremystretch commented on GitHub (Sep 29, 2016):

833499f introduced BASE_PATH which allows the user to define an arbitrary URL path via which NetBox is accessed.

18a5a96 extended the APISelect widget to use BASE_PATH. This is a bit of a hack but should be sufficient until I get around to overhauling APISelect.

@jeremystretch commented on GitHub (Sep 29, 2016): 833499f introduced `BASE_PATH` which allows the user to define an arbitrary URL path via which NetBox is accessed. 18a5a96 extended the `APISelect` widget to use `BASE_PATH`. This is a bit of a hack but should be sufficient until I get around to overhauling `APISelect`.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#159