0

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?

  • 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 Answers1

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