Display process list in Django template












0















I'm trying to implement the below example in Django and list all process inside a table but I have hard times to display the information in the template.
I ran this code in a python file and it's outputs multiple lists (one per process) as below



import psutil
for p in psutil.process_iter(attrs=['pid', 'username', 'status', 'cpu_percent', 'memory_percent', 'memory_info', 'name']):
process_info = [p.pid, p.info['username'], p.info['status'], p.info['memory_info'].rss, p.info['cpu_percent'], p.info['memory_percent'], p.info['name']]
print(process_info)

[1, 'root', 'sleeping', 9142272, 0.0, 0.009034306321108227, 'systemd']
[2, 'root', 'sleeping', 0, 0.0, 0.0, 'kthreadd']
[3, 'root', 'idle', 0, 0.0, 0.0, 'rcu_gp']
[4, 'root', 'idle', 0, 0.0, 0.0, 'rcu_par_gp']
[5, 'root', 'idle', 0, 0.0, 0.0, 'kworker/0:0-events']
[6, 'root', 'idle', 0, 0.0, 0.0, 'kworker/0:0H-kblockd']
[8, 'root', 'idle', 0, 0.0, 0.0, 'mm_percpu_wq']


How can I process all these separate lists and display them as table rows ?



Update: Here is my request in views.py



def processes(request):
for p in psutil.process_iter(attrs=['pid', 'username', 'status', 'cpu_percent', 'memory_percent', 'memory_info', 'name']):
process_info = [p.pid, p.info['username'], p.info['status'], p.info['memory_info'].rss, p.info['cpu_percent'], p.info['memory_percent'], p.info['name']]


context_processes = {'process_info': process_info }
return render(request, 'lwp_admin/processes.html', context_processes )


Below is the Django code in the template used for output:



<table class="table table-bordered table-responsive table-striped table-condensed">
<thead class="bg-green-gradient">
<tr>
<th scope="col" class="col-xs-1 text-center">PID</th>
<th scope="col" class="col-xs-1 text-center">Owner</th>
<th scope="col" class="col-xs-1 text-center">Status</th>
<th scope="col" class="col-xs-1 text-center">RSS</th>
<th scope="col" class="col-xs-1 text-center">CPU usage (%)</th>
<th scope="col" class="col-xs-1 text-center">MEM usage (%)</th>
<th scope="col" class="col-xs-3 text-center">Command</th>
</tr>
</thead>
<tbody>
{% for proc in context_processes.process_info %}
<tr>
<td>{{ proc }}</td>
</tr>
{% endfor %}
</tbody>
</table>









share|improve this question

























  • Please add your code where you tried to add that in template.

    – Sergey Pugach
    Jan 1 at 19:50
















0















I'm trying to implement the below example in Django and list all process inside a table but I have hard times to display the information in the template.
I ran this code in a python file and it's outputs multiple lists (one per process) as below



import psutil
for p in psutil.process_iter(attrs=['pid', 'username', 'status', 'cpu_percent', 'memory_percent', 'memory_info', 'name']):
process_info = [p.pid, p.info['username'], p.info['status'], p.info['memory_info'].rss, p.info['cpu_percent'], p.info['memory_percent'], p.info['name']]
print(process_info)

[1, 'root', 'sleeping', 9142272, 0.0, 0.009034306321108227, 'systemd']
[2, 'root', 'sleeping', 0, 0.0, 0.0, 'kthreadd']
[3, 'root', 'idle', 0, 0.0, 0.0, 'rcu_gp']
[4, 'root', 'idle', 0, 0.0, 0.0, 'rcu_par_gp']
[5, 'root', 'idle', 0, 0.0, 0.0, 'kworker/0:0-events']
[6, 'root', 'idle', 0, 0.0, 0.0, 'kworker/0:0H-kblockd']
[8, 'root', 'idle', 0, 0.0, 0.0, 'mm_percpu_wq']


How can I process all these separate lists and display them as table rows ?



Update: Here is my request in views.py



def processes(request):
for p in psutil.process_iter(attrs=['pid', 'username', 'status', 'cpu_percent', 'memory_percent', 'memory_info', 'name']):
process_info = [p.pid, p.info['username'], p.info['status'], p.info['memory_info'].rss, p.info['cpu_percent'], p.info['memory_percent'], p.info['name']]


context_processes = {'process_info': process_info }
return render(request, 'lwp_admin/processes.html', context_processes )


Below is the Django code in the template used for output:



<table class="table table-bordered table-responsive table-striped table-condensed">
<thead class="bg-green-gradient">
<tr>
<th scope="col" class="col-xs-1 text-center">PID</th>
<th scope="col" class="col-xs-1 text-center">Owner</th>
<th scope="col" class="col-xs-1 text-center">Status</th>
<th scope="col" class="col-xs-1 text-center">RSS</th>
<th scope="col" class="col-xs-1 text-center">CPU usage (%)</th>
<th scope="col" class="col-xs-1 text-center">MEM usage (%)</th>
<th scope="col" class="col-xs-3 text-center">Command</th>
</tr>
</thead>
<tbody>
{% for proc in context_processes.process_info %}
<tr>
<td>{{ proc }}</td>
</tr>
{% endfor %}
</tbody>
</table>









share|improve this question

























  • Please add your code where you tried to add that in template.

    – Sergey Pugach
    Jan 1 at 19:50














0












0








0








I'm trying to implement the below example in Django and list all process inside a table but I have hard times to display the information in the template.
I ran this code in a python file and it's outputs multiple lists (one per process) as below



import psutil
for p in psutil.process_iter(attrs=['pid', 'username', 'status', 'cpu_percent', 'memory_percent', 'memory_info', 'name']):
process_info = [p.pid, p.info['username'], p.info['status'], p.info['memory_info'].rss, p.info['cpu_percent'], p.info['memory_percent'], p.info['name']]
print(process_info)

[1, 'root', 'sleeping', 9142272, 0.0, 0.009034306321108227, 'systemd']
[2, 'root', 'sleeping', 0, 0.0, 0.0, 'kthreadd']
[3, 'root', 'idle', 0, 0.0, 0.0, 'rcu_gp']
[4, 'root', 'idle', 0, 0.0, 0.0, 'rcu_par_gp']
[5, 'root', 'idle', 0, 0.0, 0.0, 'kworker/0:0-events']
[6, 'root', 'idle', 0, 0.0, 0.0, 'kworker/0:0H-kblockd']
[8, 'root', 'idle', 0, 0.0, 0.0, 'mm_percpu_wq']


How can I process all these separate lists and display them as table rows ?



Update: Here is my request in views.py



def processes(request):
for p in psutil.process_iter(attrs=['pid', 'username', 'status', 'cpu_percent', 'memory_percent', 'memory_info', 'name']):
process_info = [p.pid, p.info['username'], p.info['status'], p.info['memory_info'].rss, p.info['cpu_percent'], p.info['memory_percent'], p.info['name']]


context_processes = {'process_info': process_info }
return render(request, 'lwp_admin/processes.html', context_processes )


Below is the Django code in the template used for output:



<table class="table table-bordered table-responsive table-striped table-condensed">
<thead class="bg-green-gradient">
<tr>
<th scope="col" class="col-xs-1 text-center">PID</th>
<th scope="col" class="col-xs-1 text-center">Owner</th>
<th scope="col" class="col-xs-1 text-center">Status</th>
<th scope="col" class="col-xs-1 text-center">RSS</th>
<th scope="col" class="col-xs-1 text-center">CPU usage (%)</th>
<th scope="col" class="col-xs-1 text-center">MEM usage (%)</th>
<th scope="col" class="col-xs-3 text-center">Command</th>
</tr>
</thead>
<tbody>
{% for proc in context_processes.process_info %}
<tr>
<td>{{ proc }}</td>
</tr>
{% endfor %}
</tbody>
</table>









share|improve this question
















I'm trying to implement the below example in Django and list all process inside a table but I have hard times to display the information in the template.
I ran this code in a python file and it's outputs multiple lists (one per process) as below



import psutil
for p in psutil.process_iter(attrs=['pid', 'username', 'status', 'cpu_percent', 'memory_percent', 'memory_info', 'name']):
process_info = [p.pid, p.info['username'], p.info['status'], p.info['memory_info'].rss, p.info['cpu_percent'], p.info['memory_percent'], p.info['name']]
print(process_info)

[1, 'root', 'sleeping', 9142272, 0.0, 0.009034306321108227, 'systemd']
[2, 'root', 'sleeping', 0, 0.0, 0.0, 'kthreadd']
[3, 'root', 'idle', 0, 0.0, 0.0, 'rcu_gp']
[4, 'root', 'idle', 0, 0.0, 0.0, 'rcu_par_gp']
[5, 'root', 'idle', 0, 0.0, 0.0, 'kworker/0:0-events']
[6, 'root', 'idle', 0, 0.0, 0.0, 'kworker/0:0H-kblockd']
[8, 'root', 'idle', 0, 0.0, 0.0, 'mm_percpu_wq']


How can I process all these separate lists and display them as table rows ?



Update: Here is my request in views.py



def processes(request):
for p in psutil.process_iter(attrs=['pid', 'username', 'status', 'cpu_percent', 'memory_percent', 'memory_info', 'name']):
process_info = [p.pid, p.info['username'], p.info['status'], p.info['memory_info'].rss, p.info['cpu_percent'], p.info['memory_percent'], p.info['name']]


context_processes = {'process_info': process_info }
return render(request, 'lwp_admin/processes.html', context_processes )


Below is the Django code in the template used for output:



<table class="table table-bordered table-responsive table-striped table-condensed">
<thead class="bg-green-gradient">
<tr>
<th scope="col" class="col-xs-1 text-center">PID</th>
<th scope="col" class="col-xs-1 text-center">Owner</th>
<th scope="col" class="col-xs-1 text-center">Status</th>
<th scope="col" class="col-xs-1 text-center">RSS</th>
<th scope="col" class="col-xs-1 text-center">CPU usage (%)</th>
<th scope="col" class="col-xs-1 text-center">MEM usage (%)</th>
<th scope="col" class="col-xs-3 text-center">Command</th>
</tr>
</thead>
<tbody>
{% for proc in context_processes.process_info %}
<tr>
<td>{{ proc }}</td>
</tr>
{% endfor %}
</tbody>
</table>






django django-templates






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 3 at 13:56







cioby23

















asked Jan 1 at 19:18









cioby23cioby23

10114




10114













  • Please add your code where you tried to add that in template.

    – Sergey Pugach
    Jan 1 at 19:50



















  • Please add your code where you tried to add that in template.

    – Sergey Pugach
    Jan 1 at 19:50

















Please add your code where you tried to add that in template.

– Sergey Pugach
Jan 1 at 19:50





Please add your code where you tried to add that in template.

– Sergey Pugach
Jan 1 at 19:50












2 Answers
2






active

oldest

votes


















0














Edit: based on new info
You've already created a context dictionary and assigned it to context_processes. You don't pass a dictionary of a dictionary to render().



Change your view code to:



return render(request, 'lwp_admin/processes.html', context_processes )



In your template you can loop through the passed context like this



<tr>
{% for proc in process_info %}
<td>{{ proc }}</td>
{% endfor %}
</tr>




For ref, may still be helpful on how to pass context to templates



Are you adding the dictionary you've generated into the view context? You can append to the context dictionary in your view method before passing it onto the template.



If your view is a function you just do so while building your context and pass it to the render(request, template, context) function. https://docs.djangoproject.com/en/2.1/topics/http/views/



If you are using class based views you can either, override or add get_context_data() method, depending on the base View class you are inheriting from. see example https://docs.djangoproject.com/en/2.1/topics/class-based-views/generic-display/#adding-extra-context



In your template you can access the context values via the key you saved to it. e.g



{{ name }}
{{ pid }}
{{ username }}


see template docs https://docs.djangoproject.com/en/2.1/topics/templates/#variables
hope that helps






share|improve this answer

































    0














    OK finally I managed to solve this:



    the views.py code is listed below



    def processes(request):
    proc_objects =
    for p in psutil.process_iter(attrs=['pid', 'username', 'cpu_percent', 'memory_percent', 'memory_info', 'name']):
    process_info = [p.pid, p.info['username'], round(p.info['memory_info'].rss), p.info['cpu_percent'],p.info['memory_percent'], p.info['name']]
    proc_objects.append(process_info)
    td_buttons = ['hangup', 'terminate', 'kill']

    context_processes = {'proc_objects': proc_objects, 'td_buttons': td_buttons }
    return render(request, 'lwp_admin/processes.html', context_processes)


    The template code is for this is listed below:



     <table class="table table-bordered table-responsive table-striped table-condensed">
    <thead class="bg-maroon-gradient">
    <tr>
    <th scope="col" class="col-xs-1 text-center">PID</th>
    <th scope="col" class="col-xs-1 text-center">Owner</th>
    <th scope="col" class="col-xs-1 text-center">RSS</th>
    <th scope="col" class="col-xs-1 text-center">CPU usage (%)</th>
    <th scope="col" class="col-xs-1 text-center">MEM usage (%)</th>
    <th scope="col" class="col-xs-3 text-center">Command</th>
    <th scope="col" class="text-center">Hang Up</th>
    <th scope="col" class="text-center">Terminate</th>
    <th scope="col" class="text-center">Kill</th>
    </tr>
    </thead>
    <tbody>
    {% for process_info in proc_objects %}
    <tr class="text-center">
    {% for proc in process_info %}
    <td>{{ proc }}</td>
    {% endfor %}
    <td><button type="button" class="btn btn-primary">Hang Up</button></td>
    <td><button type="button" class="btn btn-warning">Terminate</button></td>
    <td><button type="button" class="btn btn-danger">Kill</button></td>
    </tr>
    {% endfor %}
    </tbody>
    </table>


    The output for this is:
    [process list[1]






    share|improve this answer

























      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53998253%2fdisplay-process-list-in-django-template%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      0














      Edit: based on new info
      You've already created a context dictionary and assigned it to context_processes. You don't pass a dictionary of a dictionary to render().



      Change your view code to:



      return render(request, 'lwp_admin/processes.html', context_processes )



      In your template you can loop through the passed context like this



      <tr>
      {% for proc in process_info %}
      <td>{{ proc }}</td>
      {% endfor %}
      </tr>




      For ref, may still be helpful on how to pass context to templates



      Are you adding the dictionary you've generated into the view context? You can append to the context dictionary in your view method before passing it onto the template.



      If your view is a function you just do so while building your context and pass it to the render(request, template, context) function. https://docs.djangoproject.com/en/2.1/topics/http/views/



      If you are using class based views you can either, override or add get_context_data() method, depending on the base View class you are inheriting from. see example https://docs.djangoproject.com/en/2.1/topics/class-based-views/generic-display/#adding-extra-context



      In your template you can access the context values via the key you saved to it. e.g



      {{ name }}
      {{ pid }}
      {{ username }}


      see template docs https://docs.djangoproject.com/en/2.1/topics/templates/#variables
      hope that helps






      share|improve this answer






























        0














        Edit: based on new info
        You've already created a context dictionary and assigned it to context_processes. You don't pass a dictionary of a dictionary to render().



        Change your view code to:



        return render(request, 'lwp_admin/processes.html', context_processes )



        In your template you can loop through the passed context like this



        <tr>
        {% for proc in process_info %}
        <td>{{ proc }}</td>
        {% endfor %}
        </tr>




        For ref, may still be helpful on how to pass context to templates



        Are you adding the dictionary you've generated into the view context? You can append to the context dictionary in your view method before passing it onto the template.



        If your view is a function you just do so while building your context and pass it to the render(request, template, context) function. https://docs.djangoproject.com/en/2.1/topics/http/views/



        If you are using class based views you can either, override or add get_context_data() method, depending on the base View class you are inheriting from. see example https://docs.djangoproject.com/en/2.1/topics/class-based-views/generic-display/#adding-extra-context



        In your template you can access the context values via the key you saved to it. e.g



        {{ name }}
        {{ pid }}
        {{ username }}


        see template docs https://docs.djangoproject.com/en/2.1/topics/templates/#variables
        hope that helps






        share|improve this answer




























          0












          0








          0







          Edit: based on new info
          You've already created a context dictionary and assigned it to context_processes. You don't pass a dictionary of a dictionary to render().



          Change your view code to:



          return render(request, 'lwp_admin/processes.html', context_processes )



          In your template you can loop through the passed context like this



          <tr>
          {% for proc in process_info %}
          <td>{{ proc }}</td>
          {% endfor %}
          </tr>




          For ref, may still be helpful on how to pass context to templates



          Are you adding the dictionary you've generated into the view context? You can append to the context dictionary in your view method before passing it onto the template.



          If your view is a function you just do so while building your context and pass it to the render(request, template, context) function. https://docs.djangoproject.com/en/2.1/topics/http/views/



          If you are using class based views you can either, override or add get_context_data() method, depending on the base View class you are inheriting from. see example https://docs.djangoproject.com/en/2.1/topics/class-based-views/generic-display/#adding-extra-context



          In your template you can access the context values via the key you saved to it. e.g



          {{ name }}
          {{ pid }}
          {{ username }}


          see template docs https://docs.djangoproject.com/en/2.1/topics/templates/#variables
          hope that helps






          share|improve this answer















          Edit: based on new info
          You've already created a context dictionary and assigned it to context_processes. You don't pass a dictionary of a dictionary to render().



          Change your view code to:



          return render(request, 'lwp_admin/processes.html', context_processes )



          In your template you can loop through the passed context like this



          <tr>
          {% for proc in process_info %}
          <td>{{ proc }}</td>
          {% endfor %}
          </tr>




          For ref, may still be helpful on how to pass context to templates



          Are you adding the dictionary you've generated into the view context? You can append to the context dictionary in your view method before passing it onto the template.



          If your view is a function you just do so while building your context and pass it to the render(request, template, context) function. https://docs.djangoproject.com/en/2.1/topics/http/views/



          If you are using class based views you can either, override or add get_context_data() method, depending on the base View class you are inheriting from. see example https://docs.djangoproject.com/en/2.1/topics/class-based-views/generic-display/#adding-extra-context



          In your template you can access the context values via the key you saved to it. e.g



          {{ name }}
          {{ pid }}
          {{ username }}


          see template docs https://docs.djangoproject.com/en/2.1/topics/templates/#variables
          hope that helps







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Jan 2 at 2:04

























          answered Jan 1 at 20:21









          alfandangoalfandango

          4616




          4616

























              0














              OK finally I managed to solve this:



              the views.py code is listed below



              def processes(request):
              proc_objects =
              for p in psutil.process_iter(attrs=['pid', 'username', 'cpu_percent', 'memory_percent', 'memory_info', 'name']):
              process_info = [p.pid, p.info['username'], round(p.info['memory_info'].rss), p.info['cpu_percent'],p.info['memory_percent'], p.info['name']]
              proc_objects.append(process_info)
              td_buttons = ['hangup', 'terminate', 'kill']

              context_processes = {'proc_objects': proc_objects, 'td_buttons': td_buttons }
              return render(request, 'lwp_admin/processes.html', context_processes)


              The template code is for this is listed below:



               <table class="table table-bordered table-responsive table-striped table-condensed">
              <thead class="bg-maroon-gradient">
              <tr>
              <th scope="col" class="col-xs-1 text-center">PID</th>
              <th scope="col" class="col-xs-1 text-center">Owner</th>
              <th scope="col" class="col-xs-1 text-center">RSS</th>
              <th scope="col" class="col-xs-1 text-center">CPU usage (%)</th>
              <th scope="col" class="col-xs-1 text-center">MEM usage (%)</th>
              <th scope="col" class="col-xs-3 text-center">Command</th>
              <th scope="col" class="text-center">Hang Up</th>
              <th scope="col" class="text-center">Terminate</th>
              <th scope="col" class="text-center">Kill</th>
              </tr>
              </thead>
              <tbody>
              {% for process_info in proc_objects %}
              <tr class="text-center">
              {% for proc in process_info %}
              <td>{{ proc }}</td>
              {% endfor %}
              <td><button type="button" class="btn btn-primary">Hang Up</button></td>
              <td><button type="button" class="btn btn-warning">Terminate</button></td>
              <td><button type="button" class="btn btn-danger">Kill</button></td>
              </tr>
              {% endfor %}
              </tbody>
              </table>


              The output for this is:
              [process list[1]






              share|improve this answer






























                0














                OK finally I managed to solve this:



                the views.py code is listed below



                def processes(request):
                proc_objects =
                for p in psutil.process_iter(attrs=['pid', 'username', 'cpu_percent', 'memory_percent', 'memory_info', 'name']):
                process_info = [p.pid, p.info['username'], round(p.info['memory_info'].rss), p.info['cpu_percent'],p.info['memory_percent'], p.info['name']]
                proc_objects.append(process_info)
                td_buttons = ['hangup', 'terminate', 'kill']

                context_processes = {'proc_objects': proc_objects, 'td_buttons': td_buttons }
                return render(request, 'lwp_admin/processes.html', context_processes)


                The template code is for this is listed below:



                 <table class="table table-bordered table-responsive table-striped table-condensed">
                <thead class="bg-maroon-gradient">
                <tr>
                <th scope="col" class="col-xs-1 text-center">PID</th>
                <th scope="col" class="col-xs-1 text-center">Owner</th>
                <th scope="col" class="col-xs-1 text-center">RSS</th>
                <th scope="col" class="col-xs-1 text-center">CPU usage (%)</th>
                <th scope="col" class="col-xs-1 text-center">MEM usage (%)</th>
                <th scope="col" class="col-xs-3 text-center">Command</th>
                <th scope="col" class="text-center">Hang Up</th>
                <th scope="col" class="text-center">Terminate</th>
                <th scope="col" class="text-center">Kill</th>
                </tr>
                </thead>
                <tbody>
                {% for process_info in proc_objects %}
                <tr class="text-center">
                {% for proc in process_info %}
                <td>{{ proc }}</td>
                {% endfor %}
                <td><button type="button" class="btn btn-primary">Hang Up</button></td>
                <td><button type="button" class="btn btn-warning">Terminate</button></td>
                <td><button type="button" class="btn btn-danger">Kill</button></td>
                </tr>
                {% endfor %}
                </tbody>
                </table>


                The output for this is:
                [process list[1]






                share|improve this answer




























                  0












                  0








                  0







                  OK finally I managed to solve this:



                  the views.py code is listed below



                  def processes(request):
                  proc_objects =
                  for p in psutil.process_iter(attrs=['pid', 'username', 'cpu_percent', 'memory_percent', 'memory_info', 'name']):
                  process_info = [p.pid, p.info['username'], round(p.info['memory_info'].rss), p.info['cpu_percent'],p.info['memory_percent'], p.info['name']]
                  proc_objects.append(process_info)
                  td_buttons = ['hangup', 'terminate', 'kill']

                  context_processes = {'proc_objects': proc_objects, 'td_buttons': td_buttons }
                  return render(request, 'lwp_admin/processes.html', context_processes)


                  The template code is for this is listed below:



                   <table class="table table-bordered table-responsive table-striped table-condensed">
                  <thead class="bg-maroon-gradient">
                  <tr>
                  <th scope="col" class="col-xs-1 text-center">PID</th>
                  <th scope="col" class="col-xs-1 text-center">Owner</th>
                  <th scope="col" class="col-xs-1 text-center">RSS</th>
                  <th scope="col" class="col-xs-1 text-center">CPU usage (%)</th>
                  <th scope="col" class="col-xs-1 text-center">MEM usage (%)</th>
                  <th scope="col" class="col-xs-3 text-center">Command</th>
                  <th scope="col" class="text-center">Hang Up</th>
                  <th scope="col" class="text-center">Terminate</th>
                  <th scope="col" class="text-center">Kill</th>
                  </tr>
                  </thead>
                  <tbody>
                  {% for process_info in proc_objects %}
                  <tr class="text-center">
                  {% for proc in process_info %}
                  <td>{{ proc }}</td>
                  {% endfor %}
                  <td><button type="button" class="btn btn-primary">Hang Up</button></td>
                  <td><button type="button" class="btn btn-warning">Terminate</button></td>
                  <td><button type="button" class="btn btn-danger">Kill</button></td>
                  </tr>
                  {% endfor %}
                  </tbody>
                  </table>


                  The output for this is:
                  [process list[1]






                  share|improve this answer















                  OK finally I managed to solve this:



                  the views.py code is listed below



                  def processes(request):
                  proc_objects =
                  for p in psutil.process_iter(attrs=['pid', 'username', 'cpu_percent', 'memory_percent', 'memory_info', 'name']):
                  process_info = [p.pid, p.info['username'], round(p.info['memory_info'].rss), p.info['cpu_percent'],p.info['memory_percent'], p.info['name']]
                  proc_objects.append(process_info)
                  td_buttons = ['hangup', 'terminate', 'kill']

                  context_processes = {'proc_objects': proc_objects, 'td_buttons': td_buttons }
                  return render(request, 'lwp_admin/processes.html', context_processes)


                  The template code is for this is listed below:



                   <table class="table table-bordered table-responsive table-striped table-condensed">
                  <thead class="bg-maroon-gradient">
                  <tr>
                  <th scope="col" class="col-xs-1 text-center">PID</th>
                  <th scope="col" class="col-xs-1 text-center">Owner</th>
                  <th scope="col" class="col-xs-1 text-center">RSS</th>
                  <th scope="col" class="col-xs-1 text-center">CPU usage (%)</th>
                  <th scope="col" class="col-xs-1 text-center">MEM usage (%)</th>
                  <th scope="col" class="col-xs-3 text-center">Command</th>
                  <th scope="col" class="text-center">Hang Up</th>
                  <th scope="col" class="text-center">Terminate</th>
                  <th scope="col" class="text-center">Kill</th>
                  </tr>
                  </thead>
                  <tbody>
                  {% for process_info in proc_objects %}
                  <tr class="text-center">
                  {% for proc in process_info %}
                  <td>{{ proc }}</td>
                  {% endfor %}
                  <td><button type="button" class="btn btn-primary">Hang Up</button></td>
                  <td><button type="button" class="btn btn-warning">Terminate</button></td>
                  <td><button type="button" class="btn btn-danger">Kill</button></td>
                  </tr>
                  {% endfor %}
                  </tbody>
                  </table>


                  The output for this is:
                  [process list[1]







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Jan 3 at 20:12

























                  answered Jan 3 at 19:05









                  cioby23cioby23

                  10114




                  10114






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53998253%2fdisplay-process-list-in-django-template%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Monofisismo

                      Angular Downloading a file using contenturl with Basic Authentication

                      Olmecas