标签:shell
views.py
from django.shortcuts import render,render_to_response from django.http import HttpResponse import os # Create your views here. def cpu_status(request): cpu_info = os.popen(‘sar 1 1‘).read() html = ‘<html><body><pre>%s</pre></body></html>‘ % cpu_info return HttpResponse(html) def disk(request): d_usage = os.popen(‘df -h‘).read().split(‘\n‘) name_list = {‘shw‘:[26, ‘engineer‘, ‘male‘], ‘alex‘:[25, ‘sale‘, ‘female‘],} return render_to_response(‘disk.html‘, {‘d_usage‘: d_usage, ‘names‘: name_list})
disk.html
<html> <body> <p style=‘color:blue‘> This is my first website.</p> <p style=‘color:orange‘>stuff info:</p> {% for name,info in names.items %} <li>{{ name }}</li> {% for item in info %} <ul> {% ifequal item 25 %} <li>{{ item }},By failing to prepare, you are preparing to fail.</li> {% else %} <li>{{ item }}</li> {% endifequal %} </ul> {% endfor %} {% endfor %} {% for i in d_usage %} {% if "/dev/sda2" in i %} <p style=‘color:red‘>{{ i }}</p> {% else %} <p>{{ i }}</p> {% endif %} {% endfor %} </body> </html>
前端显示:
标签:shell
原文地址:http://dragonball.blog.51cto.com/1459915/1604744