Skip to content

Instantly share code, notes, and snippets.

@firedfox
Last active June 12, 2018 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save firedfox/a4cc266e16b6ae84a136fe83a8d26459 to your computer and use it in GitHub Desktop.
Save firedfox/a4cc266e16b6ae84a136fe83a8d26459 to your computer and use it in GitHub Desktop.
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>demo</title>
</head>
<body>
<h3>用户的输入</h3>
<form id="demo-form">
<label>姓名 <input name="name" type="text"></label>
<button type="submit">提交</button>
</form>
<h3>服务端返回的结果</h3>
<div id="result"></div>
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script>
$('#demo-form').on('submit', function (e) {
e.preventDefault();
var name = $('[name=name]').val();
var url = '/8000/?name=' + encodeURIComponent(name);
$.ajax({
url: url,
success: function (data) {
$('#result').text(data);
},
error: function (err) {
alert(err.statusText);
}
});
});
</script>
</body>
</html>
import sys
print('hello ' + str(sys.argv[1]))
from django.shortcuts import render
from django.http import HttpResponse
import subprocess
# Create your views here.
def index(request):
name = request.GET['name'];
output = subprocess.check_output(['python', 'somescript.py', name]).decode('utf-8')
return HttpResponse(output)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment