Displaying the contents of a Linux server on a Web page
Django Project name: Minicms
/home/username/minicms
App name in Project: News
/home/username/minicms/news
Related documents:/tmp/abc.txt
# cat /tmp/abc.txt company public Network IP address: 183.54.15.11 server memory:192.168.1.1total used free shared buffers cachedmem: 742 691 50 0 31 88-/+ buffers/cache: 571 170Swap: 991 817 174192.168.1.2total used free shared buffers cachedmem: 742 691 50 0 31 88-/+ buffers/cache: 571 170Swap: 991 817 174
views.py File:/home/username/minicms/news/views.py
#coding: Utf-8from django.http import httpresponsefrom django.shortcuts import renderimport osimport 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列表, passed to the home.html template return rend ER (request, ' home.html ', {' alist ': List}) # return render (Request, ' home.html ')
urls.py File:/home/username/minicms/minicms/urls.py
#辣鸡51, this code is sent out to show, I still do.
650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M00/99/2A/wKioL1lE0FiCNYjtAAAjuCBuyHg924.png "title=" Urls.png "alt=" Wkiol1le0ficnyjtaaajucbuyhg924.png "/>
home.html template file:/home/username/minicms/news/templates/home.html
<! DOCTYPE html>
Page Show:
650) this.width=650; "Src=" https://s1.51cto.com/wyfs02/M02/99/2A/wKiom1lEzTnjs2eFAADqFafG98A316.png-wh_500x0-wm_ 3-wmp_4-s_1510248507.png "title=" page shows. png "alt=" wkiom1leztnjs2efaadqfafg98a316.png-wh_50 "/>
This article is from the "obsessed" blog, make sure to keep this source http://dragondragon.blog.51cto.com/6170889/1939323
Django Displays the text content of a Linux server on a Web page