標籤: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.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 檔案:/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列表,傳遞給home.html模版 return render(request,‘home.html‘,{‘aList‘:List}) # return render(request, ‘home.html‘)
urls.py檔案:/home/username/minicms/minicms/urls.py
#辣雞51,這段代碼發出來不顯示,我還是吧。
650) this.width=650;" src="https://s3.51cto.com/wyfs02/M00/99/2A/wKioL1lE0FiCNYjtAAAjuCBuyHg924.png" title="urls.png" alt="wKioL1lE0FiCNYjtAAAjuCBuyHg924.png" />
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>
頁面展示:
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="頁面展示.png" alt="wKiom1lEzTnjs2eFAADqFafG98A316.png-wh_50" />
本文出自 “鬼迷心竅” 部落格,請務必保留此出處http://dragondragon.blog.51cto.com/6170889/1939323
Django在web頁面展示linux伺服器的常值內容