3

我想创建实时 cli 我正在发送带有输入 (netmiko) 的命令,我在文本 aria 中接收结果,但它不适用于我的脚本:

<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> -->

这是我的模板:

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>

这是我的观点,我用'RTR'连接到decice,我使用一个列表(输出)来显示结果

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)
4

0 回答 0