Correct way to do async forms

136 views
Skip to first unread message

Jonty Needham

unread,
Nov 27, 2015, 8:08:02 PM11/27/15
to django...@googlegroups.com

Hi,
I need to do a file upload in django where if the file fails appropriate checks then an error is raised back to the user without 500ing the page.

I've got a form that does what I want, however it returns the error in a new page, but I want it returned in place. So I need an async call. What's the correct easy to do all this? I've seen a method on line where I need to write another view to take care of the form data but that seems ugly. It seems like there should be a better easy in django.

Thanks in advance.
Jonty

Abu Ashraf Masnun

unread,
Nov 28, 2015, 11:06:58 AM11/28/15
to Django users
Hi, 

If you want to do it async, you need to use JavaScript to make ajax requests. And you need an endpoint that would respond to your ajax request. You can use the same django view to both serve the html and handle the JS request. However, that might make the business logic more complex. I would usually have a separate view for it. 

Regards,
Masnun

Saverio Trioni

unread,
Nov 29, 2015, 3:42:41 PM11/29/15
to Django users
I like to borrow rails-ujs library which enables very easy async links, forms and much more with just few HTML attributes (<a data-remote="true" > and similar. ). You can just bind on the "ajax:success" event on your form/link to react on the response.

Luis Zárate

unread,
Nov 29, 2015, 9:41:38 PM11/29/15
to django...@googlegroups.com




--
"La utopía sirve para caminar" Fernando Birri


Reply all
Reply to author
Forward
0 new messages