【发布时间】:2017-05-19 08:29:33
【问题描述】:
在 heroku 域上,我无法加载我的媒体(使用 ImageField 属性保存的图像)文件图像。但是,如果我设置debug = True,我可以看到保存在静态字段中的图像
我使用以下命令保存图像:
image = models.ImageField(upload_to=upload_location, null=True, blank=True, width_field="width_field", height_field = "height_field")
我可以通过执行以下操作在我的模板中引用它们:
<img src="{{ instance.image.url }}" class="img-responsive">
实例是从我的views.py 传递过来的:
instance = get_object_or_404(Post,slug=slug)
if instance.draft or instance.publish > timezone.now().date():
if not request.user.is_staff or not request.user.is_superuser:
raise Http404
share_string = quote_plus(instance.content)
context = {
"title": "Detail",
"instance": instance,
"share_string":share_string,
}
return render(request,"post_detail.html",context)
谢谢
【问题讨论】:
-
您仍然没有提供有关您如何尝试提供这些文件的任何信息。