user2728024
user2728024

Reputation: 1546

Dynamically load data in django template

I am using django to create an application that read data from sql server and show it on the webpage.

I want the content to change based on selected options from the drop down.

Basically I have written queries ion the model and I want my model to load content dynamically. How can I do that?

I am trying to use ajax.

Upvotes: 0

Views: 1031

Answers (1)

jsfan
jsfan

Reputation: 1373

Django won't care a whole lot about what you want to do there. Essentially, you want to create controller actions in Django that serve e.g. JSON representations of the data you want to display.

Your template then needs to include Javascript which makes the AJAX calls to retrieve data from those actions and display it on the page. You can either do this manually using just Javascript or jQuery or you can use a framework like AngularJS. The latter is heavier weight but will save you some effort if this about more than just a simple page.

There are plenty of tutorials on the web for using Django with jQuery or AngularJS which you should easily find using your favourite search engine.

Upvotes: 1

Related Questions