Py学习  »  问与答

views.py调用类实例后进行固化问题请教

lklkxcxc • 8 年前 • 2063 次点击  

请教调用问题,其中if之后内容在第一次调用get的时候肯定会执行,第二次往后就是post,elif中开始执行。但是之前第一次调用if的初始化client实例,在第二次elif中就不在了,有什么办法做得到第一次调用后就将client实例固化下来:

def remote(request,host):
user = request.user
error = ''
host = host
if request.method == 'GET':
   try:
     client = ssh.remote(host)
   except:
     error = 'ssh 连接失败,请检查主机ssh状态!'
elif request.method == 'POST':
   cmd = request.POST.get('content')
   recv_buffer = client.cmd(cmd)
   content = recv_buffer.split('\r')
   return HttpResponse(json.dumps({"content":content}))
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/1546
 
2063 次点击  
文章 [ 2 ]  |  最新文章 8 年前