Django 简单尝试
增加:setting.py
TEMPLATE_DIRS = (
'D:/TOOL/PycharmProjects/Django/templates',
)
views.py
from django.shortcuts import render_to_response
import os
def disk(request):
d_usage = os.popen('wmic cpu').read().split()
name_list = {
'php':[28,'man','It'],
'java':[33,'male','oralce'],
'python':[34,'boy','jiayou']
}
return render_to_response("diskstatus.html",{"disk_usage":d_usage,"names":name_list})
urls.py
urlpatterns = [
#url(r'^admin/', include(admin.site.urls)),
url(r'^view/$',sayhi),
url(r'^time/$',current_time),
url(r'^dir/$',win_cpu),
#url(r'^date/plus/(\d{1,2})/$',hours_ahead),
url(r'^disk/$',disk),
diskstatus.html 页面
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>目录</title>
</head>
<body>
<ul>
{% for name ,info in names.items %}
<li>{{ name }}</li>
{% for i in info %}
<ul>
{% ifequal 34 i %}
<li>{{ i }} congratulations ! you are still very young! </li>
{% else %}
<li>{{ i }}</li>
{% endifequal %}
</ul>
{% endfor %}
{% endfor %}
</ul>
<p>开始学习!!!</p>
<p>你好</p>
{% for line in disk_usage %}
{{ line }}
{% endfor %}
</body>
</html>
结果:
本文转自 知止内明 51CTO博客,原文链接:http://blog.51cto.com/357712148/2047526,如需转载请自行联系原作者