Skip to main content
 首页 » 编程设计

python之django 从 View 重定向到 iframe 的父级

2025年05月04日22jiqing9006

我有一个通过 iframe 呈现的网页。在 iframe 中成功提交表单后,我给出了,

 return HttpResponseRedirect("www.google.com") 

但目标页面也在 iframe 中加载。如何指定要从 Django View 重新加载的父级?

请您参考如下方法:

只返回一些html:

redirect_template.html:

<html> 
    <head> 
        <script> 
            window.top.location.href = '{{ redirect_url }}'; 
        </script> 
    </head> 
    <body></body> 
</html> 

代替:

return HttpResponseRedirect("www.google.com") 

使用:

return TemplateResponse(request, 'redirect_template.html', {'redirect_url':'www.google.com'}