Dynamic Buttons/Images with Django and Mongodb

I have a MQTT Client that logs messages to mongodb. I would like to use Django to dynamically create a webpage with a image or button on it depending on the last insert to the database. For example there will either be a 0 or 1 if the latest insert was a 0 display a green power button if it was 1 display a red power button. Also on the pressing of that button it performs a command and inserts the opposite value in the database. Is this possible and if so how?

Answers


To specifically answer your question, one of the ways to achieve what you want is by using CSS and jQuery. You could use other libraries you are comfortable with or even do vanilla HTML.

Use CSS to change the color of the button depending on the last insert's value. Then use jQuery's on() function to handle the click event and trigger a AJAX request to the Django backend to invoke a function that does what you want.


Need Your Help

Matlab indexing into 2D array using

matlab matrix indexing 2d

I have a 2D matrix, say M=zeros(10,10);

NSMutableArray: data missing when init with an Array

ios objective-c nsmutablearray init

As the screenshot showing, anyone who knows what's the problem of it? Thanks for kindly help!