Make csrf token available in PluginTemplateExtension #3695

Closed
opened 2025-12-29 18:30:39 +01:00 by adam · 0 comments
Owner

Originally created by @steffann on GitHub (May 16, 2020).

Originally assigned to: @steffann on GitHub.

Environment

  • Python version: 3.7.6
  • NetBox version: 2.8.4

Proposed Functionality

Currently each PluginTemplateExtension is provided a context containing object, requests, settings and config. I propose to add csrf_token to the default context.

Use Case

Writers of plugins may want to include a POST form in their template extension. This could be as simple a button for triggering or updating something. Basically for anything that has side-effects should not use GET.

A work-around is:

from django.template.context_processors import csrf

def left_page(self):
   context = {
       'abc': 'xyz',
   }
   context.update(csrf(self.context['request']))
   return self.render('pluginname/test.html', context)

My feeling is that this shouldn't be necessary and that NetBox should provide the csrf_token by default.

Database Changes

None

External Dependencies

None

Originally created by @steffann on GitHub (May 16, 2020). Originally assigned to: @steffann on GitHub. ### Environment * Python version: 3.7.6 * NetBox version: 2.8.4 ### Proposed Functionality Currently each `PluginTemplateExtension` is provided a context containing `object`, `requests`, `settings` and `config`. I propose to add `csrf_token` to the default context. ### Use Case Writers of plugins may want to include a POST form in their template extension. This could be as simple a button for triggering or updating something. Basically for anything that has side-effects should not use GET. A work-around is: ``` from django.template.context_processors import csrf def left_page(self): context = { 'abc': 'xyz', } context.update(csrf(self.context['request'])) return self.render('pluginname/test.html', context) ``` My feeling is that this shouldn't be necessary and that NetBox should provide the `csrf_token` by default. ### Database Changes None ### External Dependencies None
adam added the status: accepted label 2025-12-29 18:30:39 +01:00
adam closed this issue 2025-12-29 18:30:39 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#3695