Capturing from a html POST form a model in Django
<p>The truth i'm new to django and i would like to know how I can capture a value of an input type = hidden in a view of django, using request.POST [ 'address'] so that it can enter a value in my model in this case I want to fill my field direction but does not receive any data appears in the database as empty. This is the code I have so far:</p>

<p><strong>views.py</strong></p>

<pre><code>def formularioLleno(request):
    form = InformationForm()
    if request.method == 'POST':
        form = InformationForm(request.POST or None)
        if form.is_valid():
            form.ubicacion = request.POST['direccion']
            form.save()
            #return redirect('formas.index')
            return HttpResponseRedirect(reverse('index'))
        else:
            form = InformationForm()
    data = {
       'form': form,
    }
    return render_to_response('forma_form.html', data, context_instance=RequestContext(request))
</code></pre>

<p><strong>forms.py</strong></p>

<pre><code>from django import forms
from .models import forma
class InformationForm(forms.ModelForm):

    class Meta:
        model = forma
        fields = ('nombre', 'telefono')
</code></pre>

<p><strong>models.py</strong></p>

<pre><code>class forma(models.Model):
    nombre = models.CharField(verbose_name='nombre', max_length=50, unique=False)
    telefono = models.CharField(verbose_name='telefono', max_length=10, unique=False)
    ubicacion = models.CharField(verbose_name='ubicacion', max_length=15, unique=False)
</code></pre>

<p>forma_form.html</p>

<pre><code>&lt;div id="formularios"&gt;
{% block form_content %}
    &lt;form action="" method="POST"&gt;
        {% csrf_token %}
        {{ form.as_p }}
        &lt;div id="ubicacion"&gt;&lt;/div&gt;
        &lt;input type="hidden" id="direccion" name="direccion" value="hello"&gt;
        &lt;button type="submit" onclick="alerta()"&gt;Contactar&lt;/button&gt;
    &lt;/form&gt;

{% endblock form_content %}
</code></pre>

<p></p>

<p>The reason you aren't seeing the input is that the form field "direccion" is not a member of the class InformationForm.  When you load data from the request with <code>form = InformationForm(request.POST or None)</code> the direccion field is not captured.</p>

<p>I would recommend adding a new member to the <code>InformationForm</code> form (direccion), and set the widget to <code>HiddenInput</code> (read more about Widgets here: <a href="https://docs.djangoproject.com/en/1.10/ref/forms/widgets/" rel="nofollow">https://docs.djangoproject.com/en/1.10/ref/forms/widgets/</a>)</p>

<p>This keep the input hidden on the form but will pass the information back to the View. You can then remove the hard coded hidden input HTML from your template. </p>

python django forms input hidden