I have a project that takes a value from my website (django framework) and pass it back to django so that it can be used to run some scripts in case to dim the lights of my house (IOT project).
I've found this code in django docs tha does this by a submit button but in my case it would be better with range input. What i exactly am looking for is to send the value back every time the slider changes position just like when i press submit button.Thanks in advance.
here my code.html file
{% extends "personal/header.html" %}
{% block content %}
<form action="/code/" method="post">
{% csrf_token %}
{{ form}}
<input type="submit" value="Submit" />
</form>
{% endblock %}
And this is on my views
def get_name(request):
# if this is a POST request we need to process the form data
if request.method == 'POST':
# create a form instance and populate it with data from the request:
form = NameForm(request.POST)
# check whether it's valid:
if form.is_valid():
# process the data in form.cleaned_data as required
# ...
# redirect to a new URL:
print(form['your_name']) # outputs for example : <input type="text" name="your_name" value="34" required id="id_your_name" /> I would like to know how to print just its value :)
return HttpResponseRedirect('/code/')
# if a GET (or any other method) we'll create a blank form
else:
form = NameForm()
return render(request, 'personal/code.html', {'form': form})
And this is the forms.py file
from django import forms
class NameForm(forms.Form):
your_name = forms.DurationField(label='% Brightness ')
Here is a picture of the working code tha i want to replace with a range input instead of submit
For example something like this(Range input pic
Also this is what is happening to django (python manage.py runserver) when i submit for example the value of 345 (django shell) htt//a//ps://i.stack.imgur.com/0fMtG.png (remove the //a//)