Home > OS >  How do I create range slider in django?
How do I create range slider in django?

Time:05-31

I want this type of slider in django

I have searched a lot but I am not getting this particular slider, any help would be appreciated.

CodePudding user response:

So the frontend task of displaying the slider can be accomplished via the 3 steps in your W3 Schools link.

However with django I assume you will also want to save the user input?

You'll want to:

  1. Create a new class or add a new attribute to an existing django model class in your models.py file. Documentation
  2. Then you'll need to capture the user input so that when the user changes the slider, this updates the attribute in the database. This is started for you in step 3 of your linked doc in W3 Schools. You'll want to read up on django forms if you want this slider to update without a page reload you'll want to use something called AJAX or HTMX (recommended for modern django web development)
  3. You'll probably want the slider to load every time the user refreshes with the last point on the range that the user last left it. Something like this will do the job:

<div > <input type="range" min="1" max="100"value="{{your_model.chosen_slider_value}}" id="myRange"></div>

  • Related