I have a login and query function like this:
def login_backend(request):
if request.method == 'POST':
username = request.POST['username']
username1 = ''.join(username)
password = request.POST['password']
password = ''.join(password)
password1 = hashlib.sha1(password).hexdigest()
user = authenticate(username=username1, password=password1)
global user_id
user_id = request.user.id
if user is None:
return HttpResponseRedirect('/login_backend/')
else:
return HttpResponseRedirect('/overview/')
else:
return render_to_response('login_backend.html', context_instance=RequestContext(request))
def show_files(request):
b = File.objects.get(id=user_id) #Get the user id from session .delete() to use delete
return render_to_response('index.html', {'result': b}, context_instance=RequestContext(request)
I am getting this error:
Exception Type: NameError at /overview/
Exception Value: global name 'user_id' is not defined
What am I doing wrong?