[Answered ]-Multiple File Upload Code for Django

1πŸ‘

βœ…

I’m not sure whether I’ve missed something.

Yes : reading the error message – which tells you what the error is -, the traceback – which tells you where the error happened – and then re-reading your code. So you have:

Exception Type: TypeError
Exception Value:
cannot concatenate β€˜str’ and β€˜int’ objects

Which means you tried to concatenate a string and an integer (which Python does not allow for a quite obvious reason).

and

Exception Location: /home/michel/django/upload/index/views.py in handle_uploaded_file, line 32

which means the error is in /home/michel/django/upload/index/views.py at line 32.

Line 32 of /home/michel/django/upload/index/views.py is :

with open('/home/michel/django/upload/media/file' + count, 'wb+') as destination:

Obviously, '/home/michel/django/upload/media/file' + count is the culprit. Now you just have to fix this, either making a string of count or using string formating – both explained in the FineManual(tm).

While you’re at it, you may also want to read about the builtin enumate(sequence) function.

1πŸ‘

It concatenate error,you cannot concatenate β€˜str’ and β€˜int’ objects.

I thinks problem is at this line

'/home/michel/django/upload/media/file' + count

Solution

'/home/michel/django/upload/media/file' + str(count)

Example:

a = 'test'
b = 1
c = a+b
Type Error: cannot concatenate 'str' and 'int' objects

solution:

a = 'test'
b = str(1) or '1'
c = a+b(works fine)
πŸ‘€chandu

Leave a comment