N
N
narnik2016-09-20 11:22:12
Flask
narnik, 2016-09-20 11:22:12

Redirect to current page with new param in flask?

Hello.
The task is quite trivial, but I have been racking my brains over its solution for more than 2 days.

<div class="currenty-converter">
    <form method="post" action="" id="currency-set">
  <div class="current-currency">
      <span class="cur-label">Отображать цены в:</span><strong>{{price}}</strong>
        </div>
      <ul class="currency-list currency-toogle">
      <li>
      <a title="Dollar (USD)" href="">Долларах (USD) </a>
      </li>
      <li>
      <a title="Rubles (BYN)" href="">Рублях (BYN)</a>
      </li>
      </ul>
    </form>
</div>

There is such a simple form in base.html, and the task is simply to be able to select the type of currency from the list, after which the current page is reloaded and the parameter is changed.
I know how to do this by passing a parameter to another page, via url_for, I understand how to do it using AJAX, but in both cases, I will have to specify some specific route when the task is to leave the person on the current page, and it is not even fundamentally important whether it will reboot, or it will be done dynamically, without rebooting.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
narnik, 2016-09-20
@narnik

Works, without `context_processor`, and not quite right, but it works :) :

<div class="currenty-converter">
    <form method="post" action="" id="currency-set">
      <div class="current-currency">
        <span class="cur-label">Отображать цены в: </span><strong>{{request.args.get('v')}}</strong>

      </div>
      <ul class="currency-list currency-toogle">
        <li>
          <a title="Dollar (USD)" href="{{url_for(request.endpoint, v='USD')}}">Долларах (USD) </a>
        </li>
        <li>
          <a title="Rubles (BYN)" href="{{url_for(request.endpoint, v='BYN')}}">Рублях (BYN)</a>
        </li>
      </ul>
    </form>
  </div>

It remains only to figure out how to make this parameter so that this parameter is present on all pages by default, and adding other parameters to GET does not remove it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question