调用脚本时,Flask user\u id是否返回NoneType?

2024-09-29 23:18:42 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个小问题,就是不能在我的flask应用程序中调用用户名-我需要能够从我的应用程序中的页面调用脚本,并使用当前登录的用户名来运行部分脚本。但是,当脚本启动时,用户\u id没有类型,并且找不到登录的用户!你知道吗

下面是一些代码:

应用程序/视图/视图.py你知道吗

@app.route('/compute', methods=['GET', 'POST'])
@login_required
def compute():
    form = RadioForm(request.form)
    hlaargs = form.hlaradio.data
    print hlaargs
    form.validate_on_submit()
    if request.method == 'POST':
        if hlaargs == '1':
            id = str(uuid.uuid4())
            background_scripts[id] = False
            threading.Thread(target=lambda: run_script1(id)).start()
            return render_template('pages/processing.html', id=id)

应用程序/视图的另一部分/视图.py你知道吗

def run_script1(id):
    subprocess.call([sys.executable, "*/sshattempt1.py"])
    background_scripts[id] = True

应用程序/机器/sshattent1.py

today = datetime.date.today()
current = current_user.get_id()
usrtdy = current + '/' + str(today)
k = paramiko.RSAKey.from_private_key_file("*.pem")
c = paramiko.SSHClient()

c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
print "connecting"
....

你知道我遗漏了什么吗?我只需要用户在整个应用程序中保持一致!谢谢!你知道吗


Tags: 用户pyform脚本视图id应用程序paramiko

热门问题