"stylesheet"Type="Text/css"href="{{url_for (' static ', filename= ' Bootstrap.css ')}}"/> <script Type=text/javascript src="{{url_for (' static ', filename= ' Jquery.min.js ')}}"></script> <!--post request--<script>$ (function () {function submit_form (e) {var data= { 'name': $("#name"). val (), {#' Age ': $ ("#age"). val (), #}} $.ajax ({type:'POST', Url:'{{url_for ("test_post")}}', data:data, dataType:'text',//you want the server to return JSON-formatted data success:function (data) {alert (json.stringify (data)); var NewData=data; var table= $("#ListTable"); var body= Table.find ('Tbody:eq (0)'); Body.empty (); var tr; var Jieguo= Newdata.split ("\\n"); for(iinchJieguo) {tr= $("<tr id= ' Aaaaaaaa_"+ i +"' ></tr>"); Tr.append ($ ("<td>"+ jieguo[i]+"</td>")); Table.append (tr); } } }); } $('#button'). Bind ('Click', submit_form); }); </script>"color:red;font-size:24px;"> Please enter the Linux command: </span><input name="name"Id="name"style="widh:110px;height:30px;"Type="text"/><button id="Button" class="btn Btn-info"> Send button </button><table id="listtable"> <tbody></tbody></table>"name"style="border-bottom:darkred Solid 5px;">{{title+'\ n'}} result</span>The above is the foreground code
#-*-coding:utf-8-*- fromFlaskImportFlask, jsonify, request, render_templateImportSYSImportParamikoapp= Flask (__name__) @app. Route ('/')defHello_world ():returnRender_template ('index.html', title=" this is") @app. Route ('/test_post/', methods=['POST','GET'])deftest_post (): name=request.form.get ('name') hostname='IP'Command=str (name) Port= 22username="username"Password="pwd"s=paramiko. Sshclient () S.set_missing_host_key_policy (paramiko. Autoaddpolicy ()) s.connect (hostname, port, username, password) stdin, stdout, sterr=S.exec_command (command) z=stdout.read () s.close ( )returnJsonify ({'result': Z})if __name__=="__main__": App.run (port=7777, Debug=True)
The above is the background code
My feelings: Through this study I learned that, flask routing, jinja2, as well as the use of templates, code needs to practice daily, daily Accumulation. I'll Keep on sharing
Python flask first Experience (a) Linux command launcher