Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在html django中显示python函数结果_Python_Django - Fatal编程技术网

在html django中显示python函数结果

在html django中显示python函数结果,python,django,Python,Django,我用django制作了一个web应用程序,它执行python函数。这个函数每5秒钟运行一次,并在控制台中打印结果,我想在html页面中显示结果,并将结果扩展到html文件中以前的结果。问题是,当我按下按钮启动服务时,功能启动,但页面始终处于重新加载状态,并且不会重定向到新页面以在新页面中显示功能结果: 这是我的代码: def index(request): login_form = LoginForm(request.POST, request.FILES) context

我用django制作了一个web应用程序,它执行python函数。这个函数每5秒钟运行一次,并在控制台中打印结果,我想在html页面中显示结果,并将结果扩展到html文件中以前的结果。问题是,当我按下按钮启动服务时,功能启动,但页面始终处于重新加载状态,并且不会重定向到新页面以在新页面中显示功能结果: 这是我的代码:

def index(request):

    login_form = LoginForm(request.POST, request.FILES)

    context = {
        "form": login_form,
    }
    if login_form.is_valid():
        ip = login_form.cleaned_data.get('IP')
        port = login_form.cleaned_data.get('port')
        username = login_form.cleaned_data.get('username')
        password = login_form.cleaned_data.get('password')
        handle_uploaded_file(request.FILES["certificate"])
        request.session['ip'] = ip
        request.session['port'] = port
        request.session['username'] = username
        request.session['password'] = password
        return redirect('monitor/', request.session)

    return render(request, "index.html", context)


def monitor(request):
        ip = request.session['ip']
        port = request.session['port']
        username = request.session['username']
        password = request.session['password']
        p = sp.Popen(monitoring(ip, port, username, password), stdout=sp.PIPE, stderr=sp.PIPE)
        output, errors = p.communicate()
        return render(request, "monitor.html",{'output':output})
这是我的html: html页面

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>test</title>
    </head>
    <body>
      <h3>{{ output }}</h3>
    </body>
    </html>

测试
{{output}}