Missing Add Button in Plugin - any ideas why? #15314
Replies: 2 comments
-
Beta Was this translation helpful? Give feedback.
-
A bit late, but if anyone ends up with this problem: The issue arises because of the expected name for the urls. Basically, NetBox can't find the actual Detecting the errorOne of the ways you can detect this error is by proceeding with the tutorial anyways into the API part and creating a model. You can also do this using the vip = VideoIPathDevicetype(name='whatever', devicetype=DeviceType.objects.all()[0])
vip.save() Then, when you go back to the
Looking a bit into it, it seems Django looks for a URL with name def get_absolute_url(self):
return reverse("plugins:vip_plugin:vip", args=[self.pk]) Fixes that, but results in another error:
Let's get more in-depth hereLooking at the traceback, we eventually discover that the reverse being called is the function What is the expecteed viewname for a NetBox plugin? If you look closely you'll see that in the tutorial all url names are actually the model name in lowercase. Which is the only real difference between this code and the tutorial's code. The plugin tutorial does say:
Which is honestly a bit vague. Wait a second
Again, looking at the traceback: The actual model's method is called ( In my opinion this is non-trivial behavior, but it works if you figure it out. Should I maybe make a PR better specifying what the "naming scheme" even is for the urls, and which "several NetBox features" rely on it? Probably. TL;DRJust set the URL names to be the model name in lowercase. Even if it can be different somehow, why bother? Update your model's def get_absolute_url(self):
return reverse("plugins:vip_plugin:videoipathdevicetype", args=[self.pk]) And urls to: urlpatterns = (
path("vipdevtype/", views.VideoIPathDevicetypeListView.as_view(), name="videoipathdevicetype_list"),
path(
"vipdevtype/add/", views.VideoIPathDevicetypeEditView.as_view(), name="videoipathdevicetype_add"
),
path("vipdevtype/<int:pk>/", views.VideoIPathDevicetypeView.as_view(), name="videoipathdevicetype"),
path(
"vipdevtype/<int:pk>/edit/",
views.VideoIPathDevicetypeEditView.as_view(),
name="videoipathdevicetype_edit",
),
path(
"vipdevtype/<int:pk>/delete/",
views.VideoIPathDevicetypeDeleteView.as_view(),
name="videoipathdevicetype_delete",
),
path(
"vipdevtype/<int:pk>/changelog/",
ObjectChangeLogView.as_view(),
name="videoipathdevicetype_changelog",
kwargs={"model": models.VideoIPathDevicetype},
),
) (Better yet might be to use the actual model name as a variable and not even type it, but this works) And voilà: |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi there,
I am trying to learn the development of netbox plugins. I am currently trying to adapt the tutorial on to my own plugin. But I am stuck on a problem at step 5: views. At the end of step 5 you should see a add button on the top right to add new objects. But in my case there is no add button. Is there maybe a chance that someone could have a look at my code and maybe tell me what my error is?
Here is my code:
init.py.:
setup.py:
models.py:
tables.py:
forms.py:
views.py:
urls.py:
Beta Was this translation helpful? Give feedback.
All reactions