是否可以使用模板中Django中上传的文件?
我有一个Django模型表格,在其中我上传了应用程序的图像。我只是在本地暂时存储它们,因为它不是一个真正的项目。看上去像这样,我想知道是否有一种方法可以使用模板中每个对象上传的图像。我找不到任何文章。如何链接到与哪些模型相关联的图像?
I have a django model form where I uploaded images for my app. I am just storing them temporarily locally since its not a real project. The Admin looks like this I'm wondering if there is a way to use the images uploaded with each object in the template. I cant find any articles. How can I make a link to what images are associated with what models?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,您可以通过object.photo访问它。 url
我会向您展示一些随机示例。
由于我看不到您的模型的名称,所以让我们假装它称为帖子。
在views.py中,您可以将帖子对象发送到模板(我想您可能已经知道这一点)
view.py |示例片段
,然后您可以在模板中显示如下
index.html |示例片段
Yes you can access it through object.photo.url
I'll show u some random example.
Since I can't see the name of your model, let's pretend that it's called Post.
In views.py you can send your post objects to the templates (I guess you probably know this already)
view.py | example snippet
and then you could display it in the templates as following
index.html | example snippet