pythondjangourldjango-filtersdata-filtering

while using django_filters how to remove or edit filters field from URL


while using django_filters the url generated like this:

http://127.0.0.1:8000/reports/?EmployeeId=SW1&start_date=07%2F28%2F2021&end_date=07%2F31%2F2021

I dont want to display this things "?EmployeeId=SW1&start_date=07%2F28%2F2021&end_date=07%2F31%2F2021"

only id number should display like

http://127.0.0.1:8000/reports/1

Solution

  • When your form uses a GET method it will pass the variables in the URL. If you switch to POST in your form it won't. The url you define is your form action will be the URL people are sent to for all queries (and you'll need to also set that in your urls.py).

    You would need to switch from GET to POST in your form, to request.POST in your view, and add a CSRF token to your form. There can be additional security issues to consider so make sure to research that as well.