From 5256821b7eb5b2cfb2f06823ae23e25f920a1767 Mon Sep 17 00:00:00 2001 From: guange <8863824@gmail.com> Date: Mon, 21 Jan 2019 11:09:57 +0800 Subject: [PATCH] 1 --- chapter2/mysite/myapp/templates/myapp/crawl.html | 4 ++-- chapter2/mysite/myapp/templatetags/myapp.py | 8 +++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/chapter2/mysite/myapp/templates/myapp/crawl.html b/chapter2/mysite/myapp/templates/myapp/crawl.html index afeeaa8..07d28c0 100644 --- a/chapter2/mysite/myapp/templates/myapp/crawl.html +++ b/chapter2/mysite/myapp/templates/myapp/crawl.html @@ -119,8 +119,8 @@
  • 内存占用
    - {{platform_info.mem_total}} -

    {{platform_info.mem_used}}

    + {{platform_info.mem_total|to_g}} +

    {{platform_info.mem_used|to_g}}

  • diff --git a/chapter2/mysite/myapp/templatetags/myapp.py b/chapter2/mysite/myapp/templatetags/myapp.py index eed2b7c..6e961a3 100644 --- a/chapter2/mysite/myapp/templatetags/myapp.py +++ b/chapter2/mysite/myapp/templatetags/myapp.py @@ -6,4 +6,10 @@ register = template.Library() @register.simple_tag def present(val1, val2): """获取两个数的百分比,取整 val1 / val2 """ - return int(int(val1) * 100 / int(val2)) \ No newline at end of file + return int(int(val1) * 100 / int(val2)) + + +@register.filter +def to_g(val): + """字节到G""" + return int(int(val)/1024/1024) \ No newline at end of file