1👍
It looks like you are using a form to POST this data, but only writing to the file if the request is a GET. Try changing it to a POST. Also, since request.POST.get('genome')
should return a string for you to write to the file there is no need to wrap it in a ContentFile
. Try this:
if request.method == 'POST':
getgen = request.POST.get('genome')
with open(os.path.join(settings.MEDIA_ROOT, 'file.txt'), 'w') as f:
f.write(getgen)
I also changed your file handling to use a context manager.
Source:stackexchange.com