I have a simple Django app to show the output of an SSH remote command.
views.py:
from django.http import HttpResponse
from subprocess import *

def index(request):
    with open('/home/python/django/cron/sites.txt', 'r') as file:
        for site in file:
            # out = getoutput(f"ssh -o StrictHostKeyChecking=accept-new -p1994 root@{site} crontab -l")
            out = run(["ssh", "-o StrictHostKeyChecking=accept-new", "-p1994", f"root@{site}".strip(), "crontab", "-l"])
    return HttpResponse(out)

urls.py:
from django.contrib import admin
from django.urls import path
# imported views
from cron import views

urlpatterns = [
    path('admin/', admin.site.urls),
    # configured the url
    path('',views.index, name="homepage")
]

sites.txt:
1.1.1.1
2.2.2.2
3.3.3.3

The issue is when I run localhost:5000, I see this:
CompletedProcess(args=['ssh', '-o StrictHostKeyChecking=accept-new', '-p1994', 'root@3.3.3.3', 'crontab', '-l'], returncode=0)

While I should see something like this:
* * * * * ls
* * * * * date
* * * * * pwd

I tried with both run and getoutput, but they either don't connect or the output is shown in terminal only.
How can I run this and show the output in the webpage?

Python show output of remote SSH command in web page in Django
You're returning the CompletedProcess object instead of its output.
Try updating the run command to capture output by adding the optional parameter
out = run([...], capture_output=True)

AND changing the output to show the stdout instead of the object
return HttpResponse(out.stdout)

