Django在web页面展示linux服务器的文本内容
2017-06-17 14:35
716 查看
在web页面展示linux服务器的内容
django项目名称:minicms
/home/username/minicms
项目中app名称:news
/home/username/minicms/news
相关文件:/tmp/abc.txt
views.py 文件:/home/username/minicms/news/views.py
urls.py文件:/home/username/minicms/minicms/urls.py
#辣鸡51,这段代码发出来不显示,我还是截图吧。
![](https://s3.51cto.com/wyfs02/M00/99/2A/wKioL1lE0FiCNYjtAAAjuCBuyHg924.png)
home.html模版文件:/home/username/minicms/news/templates/home.html
页面展示:
![](https://s1.51cto.com/wyfs02/M02/99/2A/wKiom1lEzTnjs2eFAADqFafG98A316.png-wh_500x0-wm_3-wmp_4-s_1510248507.png)
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,这段代码发出来不显示,我还是截图吧。
![](https://s3.51cto.com/wyfs02/M00/99/2A/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>
页面展示:
![](https://s1.51cto.com/wyfs02/M02/99/2A/wKiom1lEzTnjs2eFAADqFafG98A316.png-wh_500x0-wm_3-wmp_4-s_1510248507.png)
相关文章推荐
- python脚本采集服务器数据通过API提交到django web服务器,然后展示在页面上
- web 框架 Django 学习记录 (二)把数据库中表内容展示在页面
- [django]在页面中正常显示包含html标记的内容,富文本信息显示
- 源码推荐(5.05):快速集成版本新特性介绍页面,可以横向展示文本内容的自定义cell,根据文本无限滚动
- websocket+Django+python+paramiko实现web页面执行服务器命令和脚本
- 网络应用发布到linux上的web服务器上页面上显示麻将牌式字符的问题
- 5 Django系列之通过list_display展示多对多与外键内容在admin-web界面下
- Linux 下 将使用Python-Django开发的web应用布置到服务器上
- Linux 下 将使用Python-Django开发的web应用布置到服务器上(亲测有效)
- web中,如何读取Word内容(包含表格,但不包含图片)并且显示在页面中或保存进数据库中
- 实现将Web页面的内容,Export To Excel的功能
- linux web服务器
- FCKeditor 一个开源的web页面文本编辑工具,在vs 2005中的使用方法
- 实现将Web页面的内容,Export To Excel的功能
- web页面中如果想让用户复制页面内容粘贴时加入一些自定义信息
- 一个多线程web服务器实例(C,Linux,详细的web服务器原理)
- 有关web页面内容文件强制下载代码
- JBoss4 应用服务器Web开发人员参考手册(8):提供静态内容服务
- 在Linux上搭建WEB服务器:基本概念、PHP zt
- JavaScript Web页面内容导出到Word、Excel