Using django filter and django table in same view

Hello,

I had a question about the following view. In this view I first request from the user input to search the database. This input is validated in forms.py . When this is valid the results are displayed in a table and a filter is shown to filter the results. The table is created with django-tables and the filter with django-filters. Then the filter is used the search terms for the filter are placed in the querydict. Since filter works with get request and only functions when querydict is populated it is placed in conditional.

My question is that this code feels redundant and also that it feels like this function is doing to much, Would there be any way to separate or make the parts seem less redundant?

Thanks,

def show_historico_accesos(request):
    if request.method == "POST":
        form = HistoricoAccesosForm(request.POST)
        if form.is_valid():
            results = get_historico_accesos(form.cleaned_data)
            request.session["historicoAccesosForm"] = form.cleaned_data
            historico_results = HistoricoAccesosFilter(request.GET, queryset=results)
            table = HistoricoAccesosTable(historico_results.qs)
            return render(
                request,
                "filter_table.html",
                {
                    "name": "Tabla de Resultados",
                    "filter": historico_results,
                    "table": table,
                },
            )
    elif request.method == "GET":
        if not request.GET:
            form = HistoricoAccesosForm()
        else:
            request.session["historicoAccesosFilter"] = request.GET.dict()
            historico_results = HistoricoAccesosFilter(request.GET, queryset=results)
            table = HistoricoAccesosTable(historico_results.qs)
            return render(
                request,
                "filter_table.html",
                {
                    "name": "Tabla de Resultados",
                    "filter": historico_results,
                    "table": table,
                },
            )
    return render(
        request,
        "form.html",
        {"form": form, "name": "Historico de Colectivos de Usuarios"},
    )