[Django]-Django posts and responses

1👍

Depending on the nature of your application, you probably shouldn’t be building the entirety of your pages with JavaScript. However, since we’re there already I’ve used the following solution with nice results:

Consider creating a template “fragment”, as I call them. It’s simply a bit of HTML that is designed to be a capsule for data transferred via AJAX. Do a render_to_response to this fragment, pass in your processed view data as variables, then retrieve this data via AJAX and use JavaScript to replace the HTML within a designated div element with the returned data.

There are some pitfalls with the above solution, such as styling and event handler attachment on the template fragment, but it should at least get you working. Just a tip in this regard, become familiar with jQuery’s .on().

0👍

pass all of the collected variables

Why don’t $(form).serialize()?

saves the values into the model

Why don’t use django.forms.ModelForm (or few of them)?

doesn’t appear to be redirecting quite right

Because redirects in AJAX are processed in AJAX call and do not affect opened page unless you process received data in JS somehow.

Also, you don’t have any data validation and|or error reporting, that’s bad. Actually, ModelForm should provide a huge help with that.

Leave a comment