0

How do I use upload_response below in my html/jquery to check if it is true or not, and display some text accordingly without going to a new page?

fileupload.py file:

  template = loader.get_template('start_interview.html')
  context = Context({ 'upload_response': 'True'})
  return HttpResponse(template.render(context))
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
user1678031
  • 2,925
  • 2
  • 16
  • 15

1 Answers1

0

You will need to use something like jquery for the ajax part.

$.ajax({
  type: "POST",
  url: "<your url to the view that returns appropriate template>",
  data: { name: "John", location: "Boston" }
}).done(function( responseMsg ) {
  $('#notifier').html(responseMsg)
});

The responseMsg will be the rendered template. There is more than one way to do the above.

In your template

{%if upload_response %}
 ...Your html tags or jquery if inside script block...
{%else%}
 ...Do Stuff if it is false...
{%endif%}
Pratik Mandrekar
  • 9,362
  • 4
  • 45
  • 65
  • Thanks - really appreciate it, I'm a newbie! So the {%if upload_response %} tags work inside script tags? – user1678031 Oct 10 '12 at 19:55
  • Yes they do! Django templating engine does not distinguish between parts of the html page or javascript as long as all of it is visible in the html i.e template variable won't work in included css/js files. – Pratik Mandrekar Oct 10 '12 at 20:00