Get the App
SLTechnology News&Howtos  ›  Servers  › 

Django displays the text content of the linux server on the web page

Shulou Source: shulou.com Published: 2022-06-03 07:36:30 09月21日 Update

Display the contents of the linux server on the web page

Django Project name: minicms

/ home/username/minicms

App name in the project: news

/ home/username/minicms/news

Related files: / tmp/abc.txt

# cat / tmp/abc.txt Public Network IP address: 183.54.15.11 Server memory: 192.168.1.1total used free shared buffers cachedMem: 742691 500388 + buffers/cache: 571170Swap: 991817 174192.168.1.2total used free shared buffers cachedMem: 742 691 500 31 88 buffers/cache + 571 170Swap: 991817 174

Views.py file: / 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): # execute the server system command os.system ("/ bin/bash / tmp/abc.sh") # Open the file fo = open ('/ tmp/abc.txt','r') # Save variable List=fo.xreadlines () # return the list list Pass to home.html template return render (request,'home.html', {'aList':List}) # return render (request,'home.html')

Urls.py file: / home/username/minicms/minicms/urls.py

# spicy Chicken 51, this code is sent out and does not show, I'd better take a screenshot.

Home.html template file: / home/username/minicms/news/templates/home.html

Test page {% for item in aList%}

{{item}}

{% endfor%}

The page is displayed:

Tags: File server service page name template project content code company memory variable command graph bar address system or public network text Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Shulou Information Linux Shulou Technology macOS