[Django]-How do I display the results of basic shell commands in a Django 1.4 website?

6👍

Use the os module to execute the command:

import os
from django.shortcuts import render

def command_view(request):
    output = os.popen('ls -l').read()
    return render(request, 'command.html', {'output': output})

And put the result of the command into the <pre> tag:

<pre>{{ output }}</pre>

Leave a comment