如何在具有相同图像名称的Django模板中显示图像

时间:2015-10-19 09:47:52

标签: django

views.py

def list_image(request):
    if form.is_valid():
        list_image = form.cleaned_data['list_image']
        return render(request, "list.html", ...) // How to give list_image to query_image

def query_image(request):
    if form.is_valid():
        query_image = form.cleaned_data['query_image'] 
        list_image = ??? //I also want to get list_image here,and display in all_image.html
        return render(request, "all_image.html", ...) 

我可以在 list.html query.html 中显示图片。

现在我想在 all_image.html 中显示来自list_imagequery_image的图片。但是怎么样?

1 个答案:

答案 0 :(得分:0)

如果query_image和list_image来自同一表单,您可以这样做:

尝试

Re-scan

你必须确保all_image.html以某种方式呈现list_image(例如,使用django templates def query_image(request): #it woul be better to rename it to all_image if form.is_valid(): query_image = form.cleaned_data['query_image'] list_image = form.cleaned_data['list_image'] my_context = {'query_image': form.cleaned_data['query_image'], 'list_image': form.cleaned_data[] #... any other data} return render(request, "all_image.html", my_context)