在Django中的模板内显示控制台输出

时间:2018-01-10 10:42:02

标签: python django

我正在开展一个项目,我正在使用Python(3.6)和Django(1.10),几天之后我很难在Django模板中显示控制台输出,但却无法找不到任何解决方案。 例如,下面的代码将各种语句打印到控制台,我想将这些消息显示给Django模板。

          if form.is_valid():
            deployment = form
            deployment.user = request.user
            deployment.project = form.cleaned_data['project']
            deployment.deploymentName = form.cleaned_data['deploymentName']
            deployment.zone = form.cleaned_data['zone']
            deployment.cluster = form.cleaned_data['cluster']
            deployment.sourceFile = form.cleaned_data['sourceFile']
            deployment.save()
            # Start awd deployment from here
            tempdir = tempfile.mkdtemp()
            saved_unmask = os.umask(0o077)
            temp_dir_path = os.path.join(tempdir)
            archive_path = os.path.join(settings.MEDIA_ROOT, 'archives/', deployment.sourceFile.name)
            print(archive_path)
            # Extract uploaded archive inside temporary dir
            patoolib.extract_archive(archive_path, outdir=temp_dir_path)
            # Try to retrieve path of dockerfile directory
            docker_glob = os.path.join(temp_dir_path, "*", "Dockerfile")
            print(docker_glob)
            docker_file = glob.glob(docker_glob)[0]
            docker_folder = os.path.dirname(docker_file)
            print(docker_folder)
            docker_client = docker.from_env()
            print("Start Building your docker image...")
            docker_client.login(username='arycloud', password='Abd37214@cloud')
            docker_client.images.build(path=docker_folder, gzip=False, tag=deployment.deploymentName)
            image = docker_client.images.get(deployment.deploymentName)
            shutil.rmtree(tempdir)
            img_id = image.short_id
            print(img_id)
            # prepare tag for image
            tag = deployment.deploymentName.lower()
            docker_api_client = docker.APIClient(
                base_url='unix://var/run/docker.sock')
            tagged = docker_api_client.tag(image=img_id, repository='arycloud/istio_dep', tag=tag, force=True)
            if tagged is True:
                print('image has been tagged!')
            print('Pushing....')
            pushing_image = docker_client.images.push(repository='arycloud/istio_dep', tag=tag)
            print(pushing_image)

0 个答案:

没有答案