I have managed to configure a system, using django, that allows me to 
upload a file to my media-folder. I have (using simple-html) included a 
drop-down menu that will specify parameters that will be considered when 
processing the uploaded file in a pipeline.

<form action="{% url "list" %}" method="post" enctype="multipart/form-data">
    <tr>
        {% csrf_token %}
        <p>{{ form.non_field_errors }}</p>

        <p>{{ form.docfile.label_tag }} {{ form.docfile.help_text }}</p>

        <p>
            {{ form.docfile.errors }}
            {{ form.docfile }}
        </p>
    </tr>

    <tr>    
    <th>Genome Dataset</th>
     <TD WIDTH = 80% ALIGN=left VALIGN=top>
      <SELECT NAME='genome' ID='genome'>
        <OPTION>All</OPTION>
        <OPTION>Neanderthal</OPTION>
        <OPTION>hg38 Human</OPTION>
        <OPTION>Denisovan</OPTION>
      </SELECT>
    </tr>   
    <p><input type="submit" value="Upload"/></p>
    </form>

I need to send the selected dropdown option to a text file. and I have 
attempted to do so as follows in views.py. However. while the file uploads 
to the media folder successfully, no text file manifests in the media 
folder- which is needed.

def GenomesView(request):
   if request.method == 'GET':
     getgen = request.GET.get('genome')
     content = ContentFile(getgen)
     f = open(os.path.join(settings.MEDIA_ROOT, 'file.txt'), 'w')
     myfile = File(f)
     myfile.write(getgen)
     myfile.close()

The location of the media folder is as below in settings.

  MEDIA_URL = '/media/'
  MEDIA_ROOT = os.path.join(BASE_DIR, 'media')

Hence my question is how do I take the selected option forms the drop-down 
and each time the file is uploaded to the site, the selection is sent to 
text file that will be over-written for each new submission (acting as a 
temporary storage for the selected option parameter i.e "Neanderthall" etc. 
as seen in code above)?


We have also tested the "tempfile" module with a generic command to create 
a temporary file within the app directory:

>>> with TemporaryFile() as f:
      f.write('abcdefg')
      f.seek(0)  # go back to the beginning
      print(f.read())


abcdefg

But this does not work either....

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/c81aed6c-a59a-452d-adad-2877b316e250%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to