I currently have a long running script which produces various output. What I want to do is have this script run when a button on my webapp is pressed, and for the output to be displayed in real time in a text area on the webpage. I was wondering the simplest way to achieve this using Django.
Yes, you can print directly to a printer from Django (or any web app) using this method.
In the Django Intro page, we learned that the result should be in HTML, and it should be created in a template, so let's do that. Create a templates folder inside the members folder, and create a HTML file named myfirst.html .
If you are talking about real time output then you need to use AJAX.
To set off the script, in the webpage you can have a button that sends an AJAX request.
function ajax_call_model(data_JSON_Request, object_id){
$(function jQuery_AJAX_model(){
$.ajax({
type: 'GET',
url: '/ajax_request/',
data: something,
datatype: "json",
success: function(data) {
$("#output_id").html(data);
},//success
error: function() {alert("failed...");}
});//.ajax
});//jQuery_AJAX
};//ajax_call
In views you will have something like this:
def ajax_request(request):
something = request.GET.get('something', '')# Receives from AJAX
output = #Does something with the request
jsonDump = json.dumps(str(output))
return HttpResponse(jsonDump, content_type='application/json')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With