My app is a db of entries that can be filtered and grouped in lists. Index page should show all entries properly paginated, with no filters, and a search form to filter by entry name and types. Is there a way to do this with one ListView and one template, changing behaviors depending if the page was accessed from index (with GET) or from a search (with POST)? If so, how can I change template page title to "Index" or "Search results" accordingly?
Asked
Active
Viewed 24 times
0
-
Does this answer your question? [Django: ListView with post() method?](https://stackoverflow.com/questions/15622354/django-listview-with-post-method) – Ankit Tiwari May 25 '22 at 07:53
1 Answers
0
Have you tried using get()
and post()
methods inside your view? It is exatcly what you need.
class YourView(ListView):
...
def get(self, request):
# unique behaviour for GET
def post(self, request, *args, **kwargs):
# unique behaviour for POST
Check out Django docs.

NixonSparrow
- 6,130
- 1
- 6
- 18
-
-
Hi @AnkitTiwari according to DOCS I've linked you can use it like this. – NixonSparrow May 25 '22 at 08:02
-
I have also used that solution in my applications many times. So yeah, it works with generic ListView. – NixonSparrow May 25 '22 at 08:33