Answer the question
In order to leave comments, you need to log in
Django: how to pass same data to different views?
Sorry for the uninformative title, it's hard to convey the whole essence of the issue in one line.
I recently started learning Django and to hone my knowledge, I'm trying to create a small engine for a certain system, or, as it's fashionable to say now: I'm creating a web application.
Now I'll get to the point. Each user has a "balance" in the system and it must be constantly visible to authorized users, regardless of which page the user is on.
For example, we have 2 views (view), let's call them buy and sell (buy and sell). Each view executes a certain code, "calls" the template (template) and passes various data to it (the template). I need the user's balance to be included in the templates without fail. How can I do that? The first thing that comes to mind is to call a function for each view that would return the balance. Like this:
def buy(request):
balance = get_balance();
return render_to_response("buy.html",{'balance':balance});
def sell(request):
balance = get_balance();
return render_to_response("sell.html",{'balance':balance});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question