I need some help please from 2 days am trying to convert a csv file of an ofx file , i have suceeded to do that but the thing just work when i specify a file and not something general what i mean :
this code work perfect :
def UploadFile(request):
if request.method == 'POST':
form = BlogForm(request.POST,request.FILES)
if form.is_valid():
form.save()
ofx = OFX(mapping)
records = read_csv("/home/mariana/django_project/media/test.csv", has_header=True)
groups = ofx.gen_groups(records)
trxns = ofx.gen_trxns(groups)
cleaned_trxns = ofx.clean_trxns(trxns)
data = utils.gen_data(cleaned_trxns)
content = it.chain([ofx.header(), ofx.gen_body(data), ofx.footer()])
with open ("/home/mariana/django_project/media/testt.ofx", 'w') as f:
res = write(f, IterStringIO(content))
print("sucess")
else:
form = BlogForm()
context = {
'form':form,
}
return render(request, 'pages/Upload.html', context)
this is my models.py :
class Blog(models.Model):
csv_file = models.FileField(null = True, upload_to='files_csv')
filename = models.CharField(max_length=20, null = True)
urlpatterns = [
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
def save(self, *args, **kwargs):
super(Blog, self).save(*args, **kwargs)
the thing doesn't work if i go that in general what i mean is if i modify :
records = read_csv("/home/mariana/django_project/media/test.csv", has_header=True)
------>
records = read_csv(request.FILES, has_header=True)
---> it doesn't work and give me an error(expected str, bytes or os.PathLike object, not MultiValueDict
) , why this !!! why when i put request.FILES doesn't work