Basic question, but I can't find a simple answer anywhere.

What is the best way to do the following in Django:

  1. User pushes button
  2. Some Python code gets crunched server-side
  3. User sees confirmation page

All the user needs to know is that the server did what he told it to. No input other than the button click.

Thanks in advance for your help.

  • I won't use this as answer, too lazy to provide any example, but here I would use JavaScript using AJAX. User pushes button, an event handler in JavaScript makes an AJAX request to the view (code gets crunched), when success a confirmation page is displayed. – Anders Jan 10 '11 at 22:18
up vote 4 down vote accepted

That's what a Form is for. You can create a small HTML form with just the button.

The form's action is the URI to which a request is sent.

Django parse the URI and calls a view function.

The function does the work and returns the resulting page.

  • Call me a newbie, but that helped a lot. Cheers! – user456584 Jan 10 '11 at 22:24

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.