Django Displays the text content of a Linux server on a Web page

Source: Internet
Author: User
Tags server memory

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.