How to change the file name of an uploaded file in Django?

0 votes

Is it possible to change the file name of an uploaded file in django? 

My requirement is whenever a file is uploaded its file name should be changed in the following format.

format = userid + transaction_uuid + file_extension.
Jul 3 in Python by kartik
• 20,980 points
60 views

1 answer to this question.

0 votes

Hello @kartik,

The basic way is

import os

os.rename('a.txt', 'b.html')

For your situation, it would probably look like

os.rename ("a.txt", "{id}{uuid}.{ext}".format(id=userid, uuid=transaction_uuid, ext=file_extension))

Hope it works!!

answered Jul 3 by Niroj
• 44,800 points

Related Questions In Python

0 votes
1 answer

How to check latest change time of each file using glob in python?

You can get the changing time from ...READ MORE

answered Jan 2, 2019 in Python by Omkar
• 69,020 points
166 views
0 votes
1 answer

How to find the value of a row in a csv file in python?

If you want to find the value ...READ MORE

answered May 20, 2019 in Python by Sanam
189 views
0 votes
1 answer
0 votes
1 answer

How to check the memory usage of an object in python

Hi, @Roshni, You can use this code below: import ...READ MORE

answered Jun 26 in Python by Gitika
• 33,770 points
68 views
0 votes
1 answer

How to temporarily disable a foreign key constraint in MySQL?

Hello @kartik, To turn off foreign key constraint ...READ MORE

answered Jun 23 in Python by Niroj
• 44,800 points
71 views
0 votes
1 answer

How do I use Django templates without the rest of Django?

Hello @kartik, Let's say you have this important ...READ MORE

answered Jun 23 in Python by Niroj
• 44,800 points
44 views
0 votes
1 answer
0 votes
1 answer

How can I get the domain name of my site within a Django template?

Hello kartik, The variation of the context processor ...READ MORE

answered Apr 23 in Python by Niroj
• 44,800 points
470 views