How can Ajax work with a dynamic Django dropdown list?

Posted by Pinki | Updated on

Want can Ajax work with a dynamic Django dropdown list? I would go for a REST service, like Django Rest Framework, and then use jquery to autopopulate the dropdowns.

If installing a REST service is a hassle, you could write a couple of views to get the data in json format. For instance, if you have a REST service in /myapp/api, you could populate the Cars like this:

Then, attach a handler when the “make” selector has changed, and populate the model and year accordingly using another REST call, like /myapp/api/cars?make=Ford.


If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.

Related Questions & Answers