Passing an argument to a view

How do I pass an argument to a view without it showing up in the url?

This works fine:
Template

<a href="{% url 'jobs:change_contract_status' job.pk %}">{{ job|contract_status_button }}</a>

urls.py

path('change_contract_status/<int:pk>/', v.change_contract_status, name='change_contract_status'),

How do I make this work?
Template

<a href="{% url 'jobs:change_contract_status' job.pk return_path=request.path %}">{{ job|contract_status_button }}</a>

urls.py

????

I don’t want the second parameter to be a part of the url.

Alternatively is there another way to make a view return to the url it was called from?

You don’t. At least not a view that is going to be accessed with a GET request.

The only data that gets passed to the view is that which is presented in the request, either as part of the URL, as query data (http://...?var=value), or as POST data in a POST request.

(Well, I guess you could set the data value in a cookie/session, and handle that in your view, that would be another option.)

2 Likes