In my Django app's views.py
I'm passing in a GET request to a function definition. How do I check for an optional parameter in that request (like &optional='All'
) and if that optional parameter is missing, add it. This is all before the request is sent to the template to be rendered.
This is what I have so far:
def my_function(request):
#get all the optional parameters
optional_params_list = request.GET.keys()
#see if filter_myfilter is NOT an optional param
if 'filter_myfilter' not in optional_params_list:
#add filter_myfilter as a parameter and set it equal to All
request.filter_myfilter = 'All'
return render(request, 'quasar.html')