我有一个项目从我的网站获取值(django框架)并将其传递回django,以便它可以用来运行一些脚本,以防昏暗的房子的灯光(物联网项目)。
我在django docs中发现了这个代码,通过提交按钮来实现这一点,但在我的情况下,使用范围输入会更好。我正在寻找的是每次滑块改变位置时发回值,就像我按下提交按钮一样。谢谢。
这里是我的code.html文件
{% extends "personal/header.html" %}
{% block content %}
<form action="/code/" method="post">
{% csrf_token %}
{{ form}}
<input type="submit" value="Submit" />
</form>
{% endblock %}
这是我的观点
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})
这是forms.py文件
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
当我提交例如 345 (django shell)的值时,这就是django(python manage.py runserver)发生的事情 htt // a // ps://i.stack.imgur.com/0fMtG.png (删除// a //)