Good afternoon, there was a very delicate question. I have a dialogue base. Which has a vendor (Owner of the base itself or where it came from.) The question is how do I transfer the name of the vendor between my pages, the first thing that occurred to me

<input name="vendor" value="{{ vendor }}" hidden> 

Read it on every request

 request.args.get('vendor') 

and redistribute further along the chain when rendering a template as a hidden field which may take a lot of code. The second sentence is to use cookies. in the app.route ("/") write a function

 cookie=request.cookies.get('vendor') retrun resp.set_cookie('vendor', 'vendor.cookie.ru') if cookie is not None retrun resp.set_cookie('vendor', 'vendor.cookie.ru') else: return redirect("set_cookie") 

Or shove it into a global variable, it can tie the login to the system and fold the question into the session that it will be faster and then less problematic.

1 answer 1

After a little deliberation, I decided to stick to the method with cookies, I put a lot easier in each process.

 vendor=get_vendor() if vendor is None: return redirect('set_cookie') 

and there are 2 such things

 @app.route("/set_cookie", methods=['GET']) def set_cookie(): vendor=request.args.get('vendor') if vendor is None : return redirect('chose_vendor') redirect_to_index = redirect('/') response = current_app.make_response(redirect_to_index) response.set_cookie('vendor', value='author24.ru') return response def get_vendor(): cookie = request.cookies.get('vendor') if cookie is not None: return cookie else: return None 

I suspect that they may ruin me for identifying a business variable in a cookie, I’d kindly need to beat it in the session and write it to g.user, but this is the way Agile works and debugging everything later.