在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)
感谢