sorl-thumbnail:缩略图字段中的随机名称

发布于 2024-08-30 18:13:40 字数 320 浏览 4 评论 0原文

我想使用 str(uuid.uuid4()) 而不是上传的名称。

我有这个模型:

class foo(models.Model):
   pic  = ThumbnailField(upload_to='pics', size=(200, 200))

我正在上传 hello_world.jpg 并且我应该保存这些命名版本,例如应保存在 4ba9b397-da69-4307-9bce-e92887e84d2f.jpg 中。

我怎样才能做到这一点?

I want to use str(uuid.uuid4()) instead of the name uploaded.

I have this model:

class foo(models.Model):
   pic  = ThumbnailField(upload_to='pics', size=(200, 200))

I am uploading hello_world.jpg and I should save these named versions should be saved for example in 4ba9b397-da69-4307-9bce-e92887e84d2f.jpg.

How can I do that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

抹茶夏天i‖ 2024-09-06 18:13:40

在你看来,你可以处理这个问题:

myfile = request.FILES['file']
foo_model = foo()
foo_model.pic.save("%s.jpg" % str(uuid.uuid4()), myfile, save=True)

You could handle this in your view:

myfile = request.FILES['file']
foo_model = foo()
foo_model.pic.save("%s.jpg" % str(uuid.uuid4()), myfile, save=True)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文