python - 将 request.GET 的响应呈现为 iframe
问题描述
我有一个 Django 视图,我需要使用一些参数对 Web 应用程序的 URL 运行 HTTP POST 请求,然后在 iframe 中显示响应。我已经实现了以下代码:
def auth_view(request):
SOME_URL = "SOME URL"
data = {"some key": "some value",}
response = requests.post(SOME_URL , data=data)
context = {'content': response.content.decode("utf-8")}
return TemplateResponse(request, template="portal/return_view.html", context=context)
对于 return_view.html,它看起来像这样:
{{ content | safe }}
这并不重要,但万一是 iframe 运行的 html 如下所示:
<body onload="document.form1.submit()">
<h1>This is the iframe view</h1>
<!-- If want to test against development -->
<form action="some_url_to_start" method="post" target="tool_content" name="form1">
<input type="hidden" name="some_param" id="some_param" value="{{ some_value }}">
<button type="submit">
Launch iframeTool
</button>
</form>
<iframe src="about:blank" width="700" height="600" name="tool_content" id="tool_content" title="Tool Content" ></iframe>
</body>
问题是返回页面正确呈现,看起来像这样:
问题:呈现的 iframe 页面内部的链接是相对的,但是当单击时,将采用父应用程序的基本 url。有没有办法让渲染的内容采用自己的源基础 url?
第二个问题:底层 iframe 应用程序实际上有一个登录机制,一旦我在这个 iframe 中实现它就无法维持。问题一定出在我这边,因为这个底层应用程序在其他站点实现的 iframe 中运行良好。如何确保登录过程持续进行?
谢谢。
解决方案
推荐阅读
- ajax - 使用 ASP.NET 核心和 AJAX 上传图像后页面正在刷新
- tensorflow - Keras 评估突然开始给出不合理的低准确度,而损失保持不变
- javascript - 如何在 ajax 调用时从 laravel 控制器函数返回视图?
- python - cx_Oracle:使用 Wallet 时如何连接到 Oracle?
- python - 替换数据框中的值仅与另一个数据框中匹配的值有关
- asp.net-core-3.1 - 如何获取当前服务健康检查的 URL?
- python - 使用变量而不是实际值会导致错误
- r - R for 循环问题:循环数据帧时“错误:$ 运算符对原子向量无效”
- javascript - 我应该避免在 Node js 上的每一个异步/等待中尝试捕获吗?
- artificial-intelligence - 简单策略游戏的 AI 技术