Issue
I have a function like this in views.py:
def signin(request):
if request.method == 'POST':
uname = request.POST['username']
pwd = request.POST['password']
#and other code
And then i have another function like this:
def reservations(request):
try:
c = Utilisateur.objects.get(username = uname)
reserve = Reserve.objects.get(client = c)
return render (request, 'reservation.html', {'reserve':reserve})
except:
return HttpResponse ('you have no reservations!')
And i want to use the "uname" variable of the first function but it doesn't work any solution?
Solution
In the first view, save the value in the session:
def signin(request):
if request.method == 'POST':
uname = request.POST['username']
request.session['uname'] = uname
Then in the second view, fetch the value from the session:
def reservations(request):
try:
uname = request.session['uname']
c = Utilisateur.objects.get(username = uname)
Answered By - John Gordon
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.