fake button run a view and come back to the same page.

67 views
Skip to first unread message

dk

unread,
Mar 10, 2015, 1:11:16 PM3/10/15
to django...@googlegroups.com
I been trying to find information on how to make a button to run a python script in the back.
I do have a table with some buttons,  and I want to click in one, and behind doors, will run a python script.

since I don't know to much javascript or flask, or php I decided to make a link (later on I can make it look like a button)  that link will run the view witch is my script as subprocess and then
return back again the view of my table,  
so basicly will click the button, will run the code, and redo the view that I was all ready in. something like this.

views:
def main_table(request):
    list_of_files= here I get my files.
    return render(request, "show_table", {"list":list_of_files})
   


def button_do_thing(request):
    file = request.GET.get(file_name)
    dosomething

    main_table(request) # here is where I am actually calling again to the main table to redraw it on the browswer.

but I get the error:
The view mes.views.test_machine didn't return an HttpResponse object. It returned None instead.
I tought passing the request should do it?

any tips, tricks?  or an actual way to make the button run the script?
thanks guys =)   .




felix

unread,
Mar 10, 2015, 2:13:43 PM3/10/15
to django...@googlegroups.com
El 10/03/15 13:11, dk escribió:
It looks like a perfect time for AJAX.
AngularJS might be an option to do it.

Daniel Roseman

unread,
Mar 10, 2015, 2:48:56 PM3/10/15
to django...@googlegroups.com
You didn't return anything at all from your do_thing view, hence the error.

However you shouldn't really call one view from the other. If you do that, the browser will show the URL of the main view, which will be confusing. Instead, after running the task, *redirect* back to the main view:

     from django.shortcuts import redirect
     ...
     return redirect('mes.views.main_table')

--
Daniel.

dk

unread,
Mar 10, 2015, 3:46:02 PM3/10/15
to django...@googlegroups.com
UHH.... redirect sounds  easy...... yami yami.....

Felix  how does the ajax works? I am assuming is a library of javascripts? and ajax can lunch the python code?

felix

unread,
Mar 10, 2015, 4:14:14 PM3/10/15
to django...@googlegroups.com
El 10/03/15 15:46, dk escribió:
UHH.... redirect sounds  easy...... yami yami.....

Felix  how does the ajax works? I am assuming is a library of javascripts? and ajax can lunch the python code?

ajax = Asynchronous Javascript And XML
It means you can update part of a page without reloading the entire page.
It is javascript in the client side. In the server side it could be any server side language/framework, including django.

Check the chapter about Ajax here. It might guide you
http://www.tangowithdjango.com/

Though if you want to use an MVC framework you could try AngularJS. Take a look at this tutorial:
http://www.w3schools.com/angular/default.asp


Reply all
Reply to author
Forward
0 new messages