0

I am trying to have an input field in the template that the user enters a query and that query goes to the views.py and from there i m taking the query and pass it as argument to the bash script.

This is what i have for now. 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>

I am stuck right here..i don't know if i shout request.POST or something else much simpler...cause i don't want to use a form.

7
  • Do you mean you don't know how to populate the form with query results? Commented Sep 29, 2017 at 14:29
  • i just want to enter the query in that input field and the query goes to the bash script...but the page is not working...i get this ValueError: The view crawler.views.home didn't return an HttpResponse object. It returned None instead. Commented Sep 29, 2017 at 14:33
  • Probably a setup issue, i.e. something is not pointing to the right place. Do other pages work? Commented Sep 29, 2017 at 14:46
  • yes...everything works fine..including calling the bash script... i even tested the function home with just a HttpResponse return...without the request.method Commented Sep 29, 2017 at 14:58
  • 1
    No, it looks like your base.html is already sending something to views. Try is_valid method to check if form is OK, just like in the post I sent above. Commented Sep 29, 2017 at 16:23

1 Answer 1

1

I figure it out by creating a script in the html template.

<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>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.