Django在web頁面展示linux伺服器的常值內容

來源:互聯網
上載者:User

標籤: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伺服器的常值內容

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.