I have to pass two parameters in every Django Request to use them in a decorator which is being called on every view of my Django application.
Currently, I am using the following way to pass parameters.
class RoleTaskForm(forms.Form):
task_id = forms.CharField(max_length=256, required=False)
action = forms.CharField(max_length=10, required=False)
Using following form in html documents
<form name="role_task_form" method="get">
<input type="hidden" name="task_id">
<input type="hidden" name="operation">
</form>
Following JS function to manipulate the form values i.e. to change the action of form accordingly and set parameter values.
function editProfile() {
let form = document.role_task_form;
form.task_id.value = "ProfileManagement";
form.operation.value = 'edit';
form.action = '/myschoolspace/edit-profile';
form.submit();
}
And call above JS function to the anchor tags of HTML pages from where we have to navigate to the views.
I am using this method to pass parameters to every request, but I feel this is not a best practice when Its necessary to pass parameters in each request.
Kindly recommend me the best way of doing it.
You can use a set of common decorators and use that in several places, you can define a list or tuple of decorators and use this instead of invoking method_decorator() multiple times. These two classes are equivalent:
Docs