I wish to assign a value from variable word in my view function one_label to the form field label in my template. I've seen some solutions with javascript but I'm not sure how to use them with the form field in the template?
<script type="text/javascript">
var myVar = "{{someDjangoVariable}}"
</script>
in models
class Labels(models.Model):
label = models.CharField()
in forms
class LabelForm(forms.Form):
label = forms.CharField(required = False)
in views
def one_label(request, postID):
one_label = Labels.objects.get(id=postID
if request.method =='POST':
form = LabelForm(request.POST)
if form.is_valid():
word = "something"
else:
form = LabelForm()
c = {"form"=form, "one_label"=one_label, "word"=word }
c.update(csrf(request))
render(response,'mytemplate.html', c)
in template
<form action="" method="post">{% csrf_token %}
{{ form.as_p}}
# assign value in var "word" in views to form field "label"
# something like {{ form.label}}:{{ word}}
</form>
{{ word }}something that comes from the views context or something else?