Python flask first Experience (a) Linux command launcher

Source: Internet
Author: User

"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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.