title: how to populate Django hidden input field of modelform with info from template?
body: <p>I've seen this asked a few times but have never seen an answer. I have a Django ModelForm with a hidden input field. I need to use info from my template for the hidden field - the 'send_to' field in this case.</p>
  
  <p>So I have the form where users can write a subject and a message, and I want to autopopulate the "to" field. </p>
  
  <p>This is my modelform: </p>
  
  <pre><code>class MessageForm(ModelForm):
  class Meta:
      model = Message
      fields = ['subject', 'message', 'send_to']
      widgets = {'send_to': forms.HiddenInput()}
  </code></pre>
  
  <p>The 'send_to' part needs to be populated with info from my template.</p>
  
  <pre><code>&lt;form method="post" action="{% url 'send' %}" id="commiserator" name="{{ c.id }}" class="write-to-user" enctype="multipart/form-data"&gt;
  &lt;h3&gt;To: {{ c.username }}&lt;/h3&gt;
  {% csrf_token %}
  
  {{message.as_p}}
  &lt;input id="commiserator" class="write-to-user" type="submit" value="Send"&gt;
  </code></pre>
  
  <p>Right now {{c.username}} is just displayed as html. I want it to be used as form input for the hidden field, but I have no idea how to do that. </p>
  
  <p>The form is being sent to the view with Ajax so I would like to make it so that the hidden information is populated before Ajax sends the data. Hope that makes sense.</p>