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, 2020 in Python by kartik
• 37,510 points
4,152 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, 2020 by Niroj
• 82,880 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,210 points
1,140 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
18,505 views
0 votes
1 answer

I want to download a file from the website by web scraping. Can anyone explain how to do this in jupyter lab (python) with an example?

Hey, Web scraping is a technique to automatically ...READ MORE

answered Apr 7, 2020 in Python by Gitika
• 65,910 points
2,075 views
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, 2020 in Python by Gitika
• 65,910 points
3,184 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, 2020 in Python by Niroj
• 82,880 points
2,043 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, 2020 in Python by Niroj
• 82,880 points
1,191 views
0 votes
1 answer
0 votes
1 answer

How to remove all of the data in a table using Django?

Hello @kartik, Inside a manager: def delete_everything(self): ...READ MORE

answered Aug 12, 2020 in Python by Niroj
• 82,880 points
3,717 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP