非公开图片上传
默认情况下,Django 将图像上传到 MEDIA_ROOT 设置,该设置被假定为可公开访问的目录。
我不希望用户能够上传图像并立即访问这些图像。相反,我希望将图像上传到非公共 tmp 目录。稍后,站点管理员将在 django-admin 中批准图像,这会将它们移动到公共图像目录。
问题是网站管理员需要能够查看 tmp 目录中存储的图像才能批准它们。因此,这些图像需要由网络服务器提供,但非版主用户无法访问。
如何:
- 扩展 ImageField 以将图像存储在 MEDIA_ROOT 以外的目录中
- 保护临时图像,以便它们在获得批准之前只能由站点管理员查看?
By default, Django uploads images to the MEDIA_ROOT setting, which is assumed to be a publicly accessible directory.
I don't want users to be able to upload images and to have those images immediately accessible. Instead, I want the images to be uploaded to a non-public tmp directory. Later on, a site moderator will approve images in django-admin, which will move them to a public image directory.
The catch is that the site moderators need to be able to view the images stored in the tmp directory in order to approve them. So, those images need to be served from the web server, but can't be accessible to users who aren't moderators.
How do I:
- Extend ImageField to store images in a directory other than MEDIA_ROOT
- Protect temporary images so that they are only viewable by site moderators before they are approved?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
回复 2:在 django 级别完全保护它们是不可能的,因为静态媒体由网络服务器提供服务,完全绕过 django。
相反,您可以做的是在媒体源中创建一个目录 /private/ 并使用正常的 apache 方式保护它 - 例如 .htaccess;
尽管之前建议的哈希对我来说似乎是更好的方法。
Re 2: completely protecting them on django level is impossible, since static media is served by the webserver, bypassing django entirely.
What you could do instead, is to create a directory /private/ in your media source and protect it using normal apache means - eg .htaccess;
Though hash, which was suggested earlier, seems like a better method to me.