0

I have a select form in django templates:

        <form action="{% url "graph" document.docfile.name %}" method="post" enctype="multipart/form-data">
        {% csrf_token %}
        <select name="{{ document.docfile.name }}" id="{{ document.docfile.name }}" onchange="this.form.submit()">
        <option value=""></option>
        {% for document in documents %}
        <option value="{{ document.docfile.name }}">{{ document.docfile.name }}</option>
        {% endfor %}
        </select>
        </form>

I want to pick the selected file in views.py. I tried request.POST.get() with no success:

if request.method == 'POST':
   doc = request.POST.get("name", "")

How can I grab the name of the selected file in python views.py?

v4graph
  • 81
  • 6
  • Your generated HTML is not valid. You can't have more than one `selected` option in a select element. But in order for us to answer, you'll need to actually post the Ajax code you're having trouble with. – Daniel Roseman Aug 29 '14 at 08:16
  • Thanks for the comment! I edit the html form and now I think it works. But I still can't grab the selected file in views.py... – v4graph Aug 29 '14 at 09:36

0 Answers0