Django passing from DropDownlist to View
<p>I am trying to get the value of the Drop-down Menu Selected. I have done the following and it is returning a 'null' value. </p>

<p>I think the problem is here: newupload = request.POST('nameProjects') but I'm not sure which on how to get it working. </p>

<p>upload.html    </p>

<pre><code>&lt;form class="form" method="POST" action="upload"&gt;
&lt;select id="ddProjects" name="nameProjects"&gt;
    {% for project in projects %}
      &lt;option value="{{ project.id }}"&gt;{{ project.name }}&lt;/option&gt;
    {% endfor %}
&lt;/select&gt;
&lt;/form&gt;
</code></pre>

<p>views.py</p>

<pre><code>def upload_new(request):
    newupload = Upload()
    projects = Project.objects.all()
    newupload.project = request.POST['nameProjects']
    newupload.save()
return render(request, 'upload.html', {'projects':projects})    
</code></pre>

<p>In the views.py, you should use request.POST['nameProjects'] because request.POST will give a dictionary.  If you want to store the project object in upload model, we need to give the project model instance variable or can give the id.</p>

<pre>
def upload_new(request):

    newupload = Upload()

    projects = Project.objects.all()

    newupload.project_id = request.POST['nameProjects']

    newupload.save()

return render(request, 'upload.html', {'projects':projects})    
</pre>

python django django-forms django-views