Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

104
Views
django real time cli with ajax

i want to create real time cli i'm sending commandes with the input (netmiko) and i recive the results in the text aria but it doesn't work my script :

<script type="text/javascript">
            $(document).('submit','#post-form',function(e)){
                e.preventDefault();
                $.ajax({
                    type:'POST',
                    url:'cli_run',
                    data:{
                        cmds:$('cmds').val(),
                        csrfmiddlewaretoken:$('input[cmds=csrfmiddlewaretoken]').val(),
                    },
                    outputs: function(data){
                        $('h2').html(data);}});}
        </script> -->

and this is my template :

div class="row">
        <div class="card col-12 col-md-6">
            <div class="card-header">
            <label> <h3>ㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤ Cli : </h3></label>
            </div>
            <br>
            <div class="card-body text-center">
            <form action="{% url 'cli_run' device.id%}" method="POST">
            {% csrf_token %}
            <textarea name="cmds" id="cmds" rows="10" cols="80"></textarea>
            <input type="submit" name="Submit">
            </form>
            </div>
        </div>



        <div class="card col-12 col-md-6">
            <div class="card-header">
            <label> <h3>output : </h3></label>
            </div>
            <br>
            <div class="card-body text-center">
            <textarea  rows="10" cols="80"> {% for i in outputs %} {{i}}     {% endfor %}    </textarea>
            </div>
        </div>

and this is my view , i connect with the decice with 'RTR' and i use a list (output ) to show the results

def cli_run(request, pk ):
    device = Device.objects.get(id=pk)

    RTR = {'ip': device.ipadress,'username': device.hostname,'password': 
     device.password,'device_type': 'cisco_ios',}
       net_connect = ConnectHandler(**RTR)
      output = net_connect.send_command(request.POST.get("cmds"))
      outputs.append(output)
    
    context = {'device':device,'output':output,'RTR':RTR,'outputs':outputs,"devices":devices}    
    return render(request, 'accounts/cli_run.html',context)
over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!