想象一下,您有一个图像供稿,一旦您点击一个图像,它就会在新模板中显示它,有点像评论视图,其中图片位于顶部,评论部分位于下方。
我唯一取得的成就是我在新标签中显示了点击后的图片:
<a href="{{image.body.url}}" target="_blank"> <img style="width:250px; background-color:yellow;flex-shrink: 0;min-width: 100%;min-height: 100%" src="{{ image.body.url }}" />
</a>
这不是我想要的......:/
所以我想象它是这样的:
希望我描述得不好。 Thx提前:))
答案 0 :(得分:1)
您的问题有点难以理解,可能是您的图片/图片网址来自数据库?如果是,则将图像的主键传递到新视图,以便可以在新模板中显示它。
答案 1 :(得分:0)
感谢@ pasta1020的回答,我做了以下内容:
的 template1.html 强>
<a href="{% url 'detail' pk=image.pk %}" >
<div style="width:250px;height:250px;" >
<img style="width:250px; background-color:yellow;" src="{{ image.body.url }}" />
</div>
</a>
的 urls.py 强>
url(r'^home/detail/(?P<pk>\d+)/$',views.detail,name='detail'),
的 views.py 强>
def detail(request,pk):
imagePk = Image.objects.get(pk=pk)
imagePkUrl = imageP.body.url
return render(request, 'template2.html', {'theSrc': imagePkUrl})
的 template2.html 强>
<img style="width:250px;height: 250px;background-color:yellow;" src="{{theSrc}}"/>