我正在尝试在模板中有一个输入字段,用户输入一个查询,然后该查询转到views.py
然后从那里开始查询并将其作为参数传递给bash脚本。
这就是我现在所拥有的。
views.py
def home(request):
if request.method == 'POST':
try:
query = request.POST['query']
test = subprocess.check_call(['home/.../bash.sh',
query])
return render(request, 'base.html', {'input': test})
except KeyError:
return HttpResponse("Nothing was submitted!")
base.html
<form action="/" method="post">
{% csrf_token %}
<input type="hidden" name="query" value="{{ input }}">
<input type="submit" value="Submit">
</form>
我被困在这里..我不知道我是否喊出request.POST或其他更简单的内容...因为我不想使用表格。
最佳答案
我通过在html模板中创建脚本来弄清楚。
<script>
$(".opener").click(function () {
var thead = $("#mytable").find("thead");
thead.find('th').last().remove();
thead = thead.html();
var row = $(this).parents('tr');
row.find('td').last().remove();
row = row.html();
var table = $(document.createElement('table'));
table.append('<thead>' + thead + '</thead>');
table.append('<tbody><tr>' + row + '</tr></tbody>')
$(".modal").html("").append(table);
$(".modal").dialog({width: 'auto', position: 'top'});
});
</script>
关于python - django将参数从模板传递到bash脚本,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/46490276/