There is such HTML located in base.html

Task: when selecting one item from the list, either apply a filter or select from the database. I understand how to do this with AJAX or SiJAX, but in this case you need to specify the route, and since it goes in base.html, from which all other pages are inherited, route cannot be used.

<div class="currenty-converter"> <form method="post" action="single-product.html#" 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> 

{{price}} is in context_processor , and I thought to try to solve it somehow through it, but now I understand that this will not work.

There is also update_template_context , but I do not understand how to use it.

  • I still do not understand what bothers you zayuzat route. Yes, it needs to be done through AJAX - andreymal
  • What route should I send? The form presented in the example is in base.html, the parameters taken from the base are in context_processor. The task is to make the dynamics not on any separate page, but on ALL pages, that is, in the base, html - Narnik Gamarnik
  • route is different on different pages, is it, or what's the problem? But even in this case, you can call url_for in the view and pass the resulting address to the template as a variable - andreymal
  • @andreymal, did not quite understand what it means to "transfer the resulting address to the template as a variable", but yes, the route is different. If you use SiJAX or AJAX, then you will have to write the same code for each route. I wish I could do the same, but with respect to variables that are in the context_processor. - Narnik Gamarnik September
  • Variables from context_processor must be successfully accessible in base.html. Either you do something wrong, or I don’t understand something because you don’t finish speaking or all at once - andreymal

1 answer 1

It works, without context_processor , and not quite as it should, 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 understand how to make this so that this parameter is present by default on all pages, and adding other parameters to the GET does not remove it.