码迷,mamicode.com
首页 > Web开发 > 详细

Django在web页面展示linux服务器的文本内容

时间:2017-06-17 15:03:12      阅读:240      评论:0      收藏:0      [点我收藏+]

标签:linux   服务器   ip地址   项目   shared   

在web页面展示linux服务器的内容

django项目名称:minicms

/home/username/minicms


项目中app名称:news

/home/username/minicms/news

相关文件:/tmp/abc.txt

# cat /tmp/abc.txt 
公司公网IP地址: 183.54.15.11
服务器内存:
192.168.1.1
total used free shared buffers cached
Mem:           742        691         50          0         31         88
-/+ buffers/cache:        571        170
Swap:          991        817        174
192.168.1.2
total used free shared buffers cached
Mem:           742        691         50          0         31         88
-/+ buffers/cache:        571        170
Swap:          991        817        174


views.py 文件:/home/username/minicms/news/views.py

#coding:utf-8
from django.http import HttpResponse
from django.shortcuts import render
import os
import subprocess

# def shell(request):
#     os.system("/bin/bash /tmp/abc.sh")
def index(request):
    #执行服务器系统命令
    os.system("/bin/bash /tmp/abc.sh")
    #打开文件
    fo = open(‘/tmp/abc.txt‘,‘r‘)
    #保存变量
    List=fo.xreadlines()
    #返回list列表,传递给home.html模版
    return render(request,‘home.html‘,{‘aList‘:List})
    # return render(request, ‘home.html‘)


urls.py文件:/home/username/minicms/minicms/urls.py

#辣鸡51,这段代码发出来不显示,我还是截图吧。

技术分享



home.html模版文件:/home/username/minicms/news/templates/home.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>test page</title>
</head>
<body>

   <div  >
        {% for item in aList %}
            <p>{{ item }},</p>
        {% endfor %}
   </div>

</body>
</html>


页面展示:

技术分享

本文出自 “鬼迷心窍” 博客,请务必保留此出处http://dragondragon.blog.51cto.com/6170889/1939323

Django在web页面展示linux服务器的文本内容

标签:linux   服务器   ip地址   项目   shared   

原文地址:http://dragondragon.blog.51cto.com/6170889/1939323

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!