[Answered ]-Generate report from Django based on user input

2👍

It wouldn’t be “current” that is in request.POST, it would be reporttype. request.POST is a dictionary-like object, so checking in will check keys, not values. The value of reporttype could be ‘Current’ or ‘All’. So just change your code so

reporttype = request.POST['reporttype']

This will set reporttype to be either All or Current (assuming you have a default set in the html – which currently you do not). You could also do what you were attempting by doing

reporttype = request.POST.get('reporttype', 'All').lower()

which will set the value to either the value passed in from the radio button, or to the default ‘All’. It also appears you want it lower cased, so sticking lower() on the end should handle that for you.

👤sberry

Leave a comment