S
S
Sergey Y2021-10-28 20:57:59
Django
Sergey Y, 2021-10-28 20:57:59

How, when a button is pressed, launch the View, while passing the context passed to this template into it?

The idea is this: there is a page with a set of records that are filtered by django-filter, the filtering works as expected, I need the user to be able to download a text file with filtered records (that is, an object passed to the template context) when clicking on a button, but all attempts to give this set of records to a new view via URLS refused to work! Need help!
And yet, is it possible to launch a View from a template, bypassing urls?

def state_list(request):
  state_search = State.objects.all()
  f = StateFilter(request.GET, queryset=state_search)
  return render(request, 'main/state_filter.html', {'filter': f})

def state_filter_save_view(request):
  pass


<div class="row">
    <div class="col-auto">
        <a href="{% url 'work:state_filter' %}">ПОКАЗАТЬ ВЕСЬ ШТАТ</a>
        <form method="get"  action="{% url 'work:state_filter' %}" >
            {{ filter.form.as_p }}
        </form>
      <form method="get" action="{% url 'work:state_filter_save' %}" >
            <input type="submit" value="Скачать">
      </form>
    </div>
    <div class="col">

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question