[Fixed]-Django File not uploading

1👍

My bad, I figured out the problem.

In my views, where I had:

if request.POST:
    if request.POST.get(str(column.unique_id)):
        if column.field_type == 23:
            DbField.objects.create(row=row ... photofield=request.FILES[str(column.unique_id)])

It was failing because request.POST.get(str(column.unique_id)) was empty since it was FILES and not POST.

I rewrote the view to accomodate:

if request.POST.get(str(column.unique_id)):
    ...
else:
    if request.FILES[str(column.unique_id)]:
        if column.field_type == 23:
            DbField.objects.create(row=row ... photofield=request.FILES[str(column.unique_id)])
        else:
            DbField.objects.create(row=row ... all other fields left blank)

This way if the request.POST for the field comes up empty, it checks to see if there’s a file attached and the correct field type, if not then it just creates the empty field.

Leave a comment