Last active
June 12, 2018 14:07
-
-
Save firedfox/a4cc266e16b6ae84a136fe83a8d26459 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
print('hello ' + str(sys.argv[1])) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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