سلام
توی جنگو نیاز به آپلود عکس داشتم و بعد از پیش رفتن با doc جنگو و یه سایت دیگه تونستم انجامش بدم اما دیدم عکسا با اسمی که توی سیستم من هست دارن ذخیره میشن
با خودم گفتم چی میشه اگه دو تا عکس با یه اسم آپلود بشه؟
توی نت سرچ کردم راه حل پیشنهادی استفاده از uuid4 بود
import uuid
ext = filename.split('.')[-1]
filename = "%s.%s" % (uuid.uuid4(), ext)
قبلا uuid رو در مورد هارد ها شنیده بودم که یه شناسه unique جهانی هست
کنجکاو شدم که چه جوری و رو چه حسابی چنین چیزی برای یه عکس تولید میشه؟
The generation of a v4 UUID is much simpler to comprehend. Each and every bit of a UUID v4 is generated randomly and with no inherent logic. It’s that simple. There is, therefore, no question of anonymity.
However, there is now a chance that a UUID could be duplicated. The question is, do you need to worry about it?
The short answer is no. With the sheer number of possible combinations (2^128), it would be almost impossible to generate a duplicate unless you are generating trillions of IDs every second, for many years. This is a laughable standard for any application in todays world, and not substantial enough to take into consideration.
طبق این توضیح فقط یه رشته random تولید میشه
خوب این رو که بدون استفاده از uuid هم میتونستم به هر شکلی و به هر طولی که خودم میخوام ایجاد کنم
احتمالش خیلی خیلی کمه اما بازم ممکنه دو تا عکس با یه اسم داشته باشم