+ 1

Really need help with Django!!

Hi, I am having a problem with my Django code. As this website does not provide anything on Django I have submitted my question on stackoverflow at the following link : https://stackoverflow.com/questions/62542089/how-to-use-django-button-as-form-input-field Hope someone can help. Thank you

25th Jun 2020, 9:43 PM
MBanski
MBanski - avatar
4 Réponses
+ 2
Hi, you could use a hidden input. #forms.py class fontform(forms.ModelForm): btn = forms.IntegerField(widget=forms.HiddenInput(attrs={'id' : 'myfieldid' }) class Meta: model = layout fields = ['btn'] #template ... <form method='POST' action='{% url 'testview' %}'> {{ form }} <span id="preview">Text Size</span> <button onclick='document.getElementById("myfieldid").value = parseInt(document.getElementById("myfieldid").value)+1;document.getElementById("preview").style.fontSize = document.getElementById("myfieldid").value + "px"'> <button onclick='document.getElementById("myfieldid").value = parseInt(document.getElementById("myfieldid").value)-1;document.getElementById("preview").style.fontSize = document.getElementById("myfieldid").value + "px"'> <input type="submit"> </form> ...
6th Jul 2020, 5:25 AM
Arnesh
Arnesh - avatar
+ 1
#views.py def test_view(request): if request.method == 'POST': form = fontform(request.POST) if form.is_valid(): form.save() else: form = fontform() return render(request, 'home.html')
6th Jul 2020, 5:28 AM
Arnesh
Arnesh - avatar
+ 1
Or perhaps you could use a range input?
6th Jul 2020, 5:29 AM
Arnesh
Arnesh - avatar