django将参数从模板传递给bash脚本

时间:2017-09-29 13:51:51

标签: python mysql django bash

我正在尝试在模板中输入一个用户输入查询的输入字段,该查询将转到 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 或其他更简单的东西...因为我不想使用表格。

1 个答案:

答案 0 :(得分:1)

我通过在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>
相关问题